-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add more platforms and build (& test) in parallel
- Loading branch information
1 parent
f9eefb0
commit 8352846
Showing
2 changed files
with
95 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,50 @@ | ||
name: Unit Tests | ||
name: Unit Tests & Tagged Deploy | ||
|
||
# based on: https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners | ||
|
||
on: | ||
push: | ||
branches: | ||
- '*' | ||
tags: | ||
- '*' | ||
- 'v*' | ||
|
||
env: | ||
REGISTRY_IMAGE: dhilsfu/doceww | ||
DB_NAME: pipeline_db | ||
DB_USER: pipeline_user | ||
DB_PASSWORD: pipeline_password | ||
|
||
|
||
jobs: | ||
unit-tests: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: | ||
# - linux/386 | ||
- linux/amd64 | ||
# - linux/arm/v5 | ||
- linux/arm/v7 | ||
- linux/arm64 | ||
# - linux/mips64le | ||
# - linux/ppc64le | ||
# - linux/s390x | ||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure sysctl limits | ||
- name: Prepare | ||
run: | | ||
sudo swapoff -a | ||
sudo sysctl -w vm.swappiness=1 | ||
sudo sysctl -w fs.file-max=262144 | ||
sudo sysctl -w vm.max_map_count=262144 | ||
platform=${{ matrix.platform }} | ||
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | ||
- name: Make .env.test.local | ||
run: | | ||
touch .env.test.local | ||
echo DATABASE_URL="mysql://doceww:[email protected]:3306/doceww?serverVersion=mariadb-10.10.0" >> .env.test.local | ||
echo ELASTICSEARCH_HOST="127.0.0.1" >> .env.test.local | ||
echo ELASTICSEARCH_PORT="9200" >> .env.test.local | ||
echo ELASTICSEARCH_USERNAME="elastic" >> .env.test.local | ||
echo ELASTICSEARCH_PASSWORD="" >> .env.test.local | ||
- name: Checkout source code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY_IMAGE }} | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
@@ -42,15 +58,26 @@ jobs: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | ||
|
||
- name: Build and push by digest | ||
id: build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
platforms: ${{ matrix.platform }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true | ||
cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }} | ||
cache-to: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }},mode=max | ||
|
||
- name: Shutdown Ubuntu MySQL (SUDO) | ||
run: sudo service mysql stop | ||
|
||
- name: Set up MariaDB | ||
uses: getong/[email protected] | ||
with: | ||
mysql database: doceww_test | ||
mysql user: doceww | ||
mysql password: password | ||
mysql database: ${{ env.DB_NAME }}_test | ||
mysql user: ${{ env.DB_USER }} | ||
mysql password: ${{ env.DB_PASSWORD }} | ||
|
||
- name: Runs Elasticsearch | ||
uses: getong/[email protected] | ||
|
@@ -62,33 +89,52 @@ jobs: | |
node port: 9300 | ||
discovery type: 'single-node' | ||
|
||
- name: Build doceww | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
load: true | ||
pull: true | ||
tags: dhilsfu/doceww:latest | ||
cache-from: type=registry,ref=dhilsfu/doceww:buildcache | ||
|
||
- name: Run Unit Tests | ||
run: | | ||
touch .env.test.local | ||
echo DATABASE_URL="mysql://${{ env.DB_USER }}:${{ env.DB_PASSWORD }}@127.0.0.1:3306/${{ env.DB_NAME }}?serverVersion=mariadb-10.11.0" >> .env.test.local | ||
echo ELASTICSEARCH_HOST="127.0.0.1" >> .env.test.local | ||
echo ELASTICSEARCH_PORT="9200" >> .env.test.local | ||
echo ELASTICSEARCH_USERNAME="elastic" >> .env.test.local | ||
echo ELASTICSEARCH_PASSWORD="" >> .env.test.local | ||
docker run --rm \ | ||
-v "${GITHUB_WORKSPACE}/.env.test.local":/var/www/html/.env.test.local \ | ||
--network host \ | ||
dhilsfu/doceww:latest make test | ||
--platform=${{ matrix.platform }} \ | ||
${{ env.REGISTRY_IMAGE }}@${{ steps.build.outputs.digest }} make test | ||
deploy-image: | ||
- name: Export digest | ||
run: | | ||
mkdir -p /tmp/digests | ||
digest="${{ steps.build.outputs.digest }}" | ||
touch "/tmp/digests/${digest#sha256:}" | ||
- name: Upload digest | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: digests-${{ env.PLATFORM_PAIR }} | ||
path: /tmp/digests/* | ||
if-no-files-found: error | ||
retention-days: 1 | ||
|
||
push: | ||
runs-on: ubuntu-latest | ||
if: startsWith(github.ref, 'refs/tags/') | ||
needs: | ||
- unit-tests | ||
- build | ||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v3 | ||
- name: Download digests | ||
uses: actions/download-artifact@v4 | ||
with: | ||
path: /tmp/digests | ||
pattern: digests-* | ||
merge-multiple: true | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY_IMAGE }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
@@ -99,16 +145,15 @@ jobs: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | ||
|
||
- name: Build & Push Symfony Base | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
pull: true | ||
tags: dhilsfu/doceww:latest,dhilsfu/doceww:${{github.ref_name}} | ||
cache-from: type=registry,ref=dhilsfu/doceww:buildcache | ||
cache-to: type=registry,ref=dhilsfu/doceww:buildcache,mode=max | ||
- name: Create manifest list and push | ||
working-directory: /tmp/digests | ||
run: | | ||
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) | ||
- name: Inspect image | ||
run: | | ||
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} | ||
- name: Trigger Gitlab Deploy Job | ||
run: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters