More new features #36
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
name: Build App Image | |
on: | |
push: | |
branches: [ master ] | |
# Publish semver tags as releases. | |
tags: [ 'v*.*.*' ] | |
pull_request: | |
branches: [ master ] | |
workflow_dispatch: | |
inputs: | |
push: | |
description: 'Push Image (true or false)' | |
type: choice | |
options: | |
- "true" | |
- "false" | |
required: true | |
run_tests: | |
description: 'Run unit tests (true or false)' | |
type: choice | |
options: | |
- "true" | |
- "false" | |
required: true | |
default: 'true' | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
# Unit test | |
DB_DATABASE: mydb | |
DB_USERNAME: root | |
DB_PASSWORD: mysqlp455w0rd | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
build_backend_app: | |
runs-on: ubuntu-latest | |
services: | |
mysql-container: | |
image: mysql:8.0 | |
env: | |
MYSQL_ALLOW_EMPTY_PASSWORD: false | |
MYSQL_ROOT_PASSWORD: ${{ env.DB_PASSWORD }} | |
MYSQL_DATABASE: ${{ env.DB_DATABASE }} | |
ports: | |
- 3306/tcp | |
options: --name mysql --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
# Login against a Docker registry to pull the GHCR image | |
# https://github.com/docker/login-action | |
- name: Log into registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
# Build image locally to enable to run the test | |
# https://github.com/docker/build-push-action | |
- name: Build Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: docker/Dockerfile | |
push: false | |
platforms: linux/amd64 #,linux/arm64 | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
load: true | |
- name: Inspect | |
run: | | |
for tag in $(echo "${{ steps.meta.outputs.tags }}"); do | |
docker image inspect $tag | |
done | |
- name: Test with phpunit | |
if: ${{ github.event.inputs.run_tests != 'false' }} | |
run: | | |
for tag in $(echo "${{ steps.meta.outputs.tags }}"); do | |
docker run \ | |
-e APP_ENV=test \ | |
-p 80:80 \ | |
--name tester \ | |
--rm -d \ | |
--network ${{ job.container.network }} \ | |
$tag tail -f /dev/null | |
docker cp tests/ tester:/srv | |
docker exec tester composer run migrate -- reset --yes | |
docker exec tester composer install --dev --no-interaction --no-progress | |
docker exec tester composer run test | |
docker stop tester | |
break | |
done | |
# PUSH the image (if isn't PR) | |
- name: Push Docker image | |
if: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }} | |
run: | | |
for tag in $(echo "${{ steps.meta.outputs.tags }}"); do | |
docker push $tag | |
done | |
- name: Job Summary | |
run: | | |
for tag in $(echo "${{ steps.meta.outputs.tags }}"); do | |
echo Docker Image: $tag | |
done | |
echo Push Image: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }} |