Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions templates/ci/github/workflows/ci.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ permissions:
contents: read
packages: write

env:
CI_IMAGE: ghcr.io/${{ github.repository }}/ci:php<?= $phpVersion ?>


jobs:
build-image:
runs-on: ubuntu-latest
outputs:
image: ${{ steps.meta.outputs.image }}
steps:
- name: Set image name
id: meta
run: echo "image=ghcr.io/${GITHUB_REPOSITORY,,}/ci:php<?= $phpVersion ?>" >> $GITHUB_OUTPUT

- uses: actions/checkout@v4

- name: Log in to GHCR
Expand All @@ -36,15 +38,15 @@ jobs:
context: .
file: .github/ci/Dockerfile
push: true
tags: ${{ env.CI_IMAGE }}
tags: ${{ steps.meta.outputs.image }}
cache-from: type=gha
cache-to: type=gha,mode=max

build:
needs: [build-image]
runs-on: ubuntu-latest
container:
image: ${{ env.CI_IMAGE }}
image: ${{ needs.build-image.outputs.image }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -95,7 +97,7 @@ jobs:
needs: [build-image, build]
runs-on: ubuntu-latest
container:
image: ${{ env.CI_IMAGE }}
image: ${{ needs.build-image.outputs.image }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -122,7 +124,7 @@ jobs:
needs: [build-image, build]
runs-on: ubuntu-latest
container:
image: ${{ env.CI_IMAGE }}
image: ${{ needs.build-image.outputs.image }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -164,11 +166,11 @@ jobs:
<?php if ($databaseType === 'postgresql'): ?>
options: --health-cmd pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
<?php else: ?>
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
options: --health-cmd="mysqladmin ping -h 127.0.0.1 -u root -p<?= $databaseEnvVars['MYSQL_ROOT_PASSWORD'] ?> --silent" --health-interval=5s --health-timeout=5s --health-retries=10
<?php endif; ?>
<?php endif; ?>
container:
image: ${{ env.CI_IMAGE }}
image: ${{ needs.build-image.outputs.image }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Expand Down
20 changes: 8 additions & 12 deletions templates/ci/gitlab-ci.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,15 @@ variables:

build:image:
stage: .pre
image:
name: gcr.io/kaniko-project/executor:v1.23.2-debug
entrypoint: [""]
image: docker:27
services:
- docker:27-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(printf '%s:%s' "$CI_REGISTRY_USER" "$CI_REGISTRY_PASSWORD" | base64)\"}}}" > /kaniko/.docker/config.json
- >-
/kaniko/executor
--context $CI_PROJECT_DIR
--dockerfile $CI_PROJECT_DIR/.gitlab/ci/Dockerfile
--destination $CI_IMAGE
--cache=true
--cache-repo $CI_REGISTRY_IMAGE/ci/cache
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -t $CI_IMAGE -f .gitlab/ci/Dockerfile .
- docker push $CI_IMAGE
rules:
- changes:
- .gitlab/ci/Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions tests/Generator/GitHubActionsGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testCiJobsUseContainer(): void

$ci = $files['.github/workflows/ci.yml'];
self::assertStringContainsString('container:', $ci);
self::assertStringContainsString('image: ${{ env.CI_IMAGE }}', $ci);
self::assertStringContainsString('image: ${{ needs.build-image.outputs.image }}', $ci);
}

public function testCiWithDatabaseUsesDatabaseHostname(): void
Expand Down Expand Up @@ -172,7 +172,7 @@ public function testCiContainsGhcrImage(): void

$files = $this->generator->generate($config);

self::assertStringContainsString('ghcr.io/${{ github.repository }}/ci:php8.4', $files['.github/workflows/ci.yml']);
self::assertStringContainsString('ghcr.io/${GITHUB_REPOSITORY,,}/ci:php8.4', $files['.github/workflows/ci.yml']);
}

public function testCiJobsNeedBuildImage(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Generator/GitLabCiGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public function testCiContainsBuildImageJob(): void

$ci = $files['.gitlab-ci.yml'];
self::assertStringContainsString('build:image:', $ci);
self::assertStringContainsString('kaniko', $ci);
self::assertStringContainsString('docker:27', $ci);
self::assertStringContainsString('docker login -u gitlab-ci-token -p $CI_JOB_TOKEN', $ci);
self::assertStringContainsString('$CI_IMAGE', $ci);
}

Expand Down