Skip to content

Bump docker/build-push-action from 1 to 5 #1720

Bump docker/build-push-action from 1 to 5

Bump docker/build-push-action from 1 to 5 #1720

name: Build and deploy
on:
push:
branches:
- master
tags:
- v**
pull_request:
branches:
- master
jobs:
test-backend:
name: Test backend
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v3
- name: Install python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10.x'
cache: 'pip'
cache-dependency-path: 'backend/requirements.txt'
- name: Install and execute 'tox'
run: |
pip install tox
tox
build-backend:
name: Build backend container
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build and push backend container image
uses: bCyberGmbH/build-container-image-action@main
with:
registry_name: docker.io
registry_username: ${{ secrets.DOCKER_HUB_USER }}
registry_password: ${{ secrets.DOCKER_HUB_PASS }}
image_repository: codeformuenster/muenster-jetzt-api
dockerfile_path: backend/deployment/Dockerfile.prod
build_context: backend
push_to_registry: ${{ github.event_name != 'pull_request' }}
- name: Build and push backend nginx container image
uses: bCyberGmbH/build-container-image-action@main
with:
registry_name: docker.io
registry_username: ${{ secrets.DOCKER_HUB_USER }}
registry_password: ${{ secrets.DOCKER_HUB_PASS }}
image_repository: codeformuenster/muenster-jetzt-api-static
dockerfile_path: backend/deployment/Dockerfile.prod
build_context: backend
build_target: staticfiles
push_to_registry: ${{ github.event_name != 'pull_request' }}
check-api-client-up-to-date:
name: Check if generated api client is up to date
runs-on: ubuntu-latest
needs: test-backend
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '2' # for comparison
- name: Gather branch information
id: branch_info
continue-on-error: true
run: |
branch_name=${GITHUB_REF##*/}
short_sha=${GITHUB_SHA:0:7}
echo "branch_name=${branch_name}" >> $GITHUB_OUTPUT
echo "short_sha=${short_sha}" >> $GITHUB_OUTPUT
echo "We're running on ${branch_name} (${short_sha})"
if [ "$branch_name" = "master" ] || [ "$GITHUB_REF_TYPE" = "tag" ]; then
echo "changes=1" >> $GITHUB_OUTPUT
else
echo "changes=$(git diff --name-only HEAD^1 -- . | wc -l)" >> $GITHUB_OUTPUT
fi
- name: Install Node.js 14
if: steps.branch_info.outputs.changes != '0'
uses: actions/setup-node@v3
with:
node-version: 14
cache: 'npm'
cache-dependency-path: 'frontend/package-lock.json'
- name: Run 'npm ci' to install frontend dependencies
if: steps.branch_info.outputs.changes != '0'
run: |
npm ci
- name: Build backend image
if: steps.branch_info.outputs.changes != '0'
uses: docker/build-push-action@v5
with:
push: false
repository: muenster-jetzt-api
dockerfile: backend/deployment/Dockerfile.prod
tags: in-ci
path: backend
always_pull: true
cache_froms: ${{ steps.branch_info.outputs.cache_from_container_image }}
- name: Start container from backend image
if: steps.branch_info.outputs.changes != '0'
run: |
docker run -d --name backend -p 8000:8000 --env-file ../backend/.env.example muenster-jetzt-api:in-ci
- name: Run 'npm run generate-client'
if: steps.branch_info.outputs.changes != '0'
run: |
sleep 10
docker logs backend
npm run generate-client
- name: Check for changes according to git
if: steps.branch_info.outputs.changes != '0'
run: |
git checkout -- ../backend/deployment/Dockerfile.prod
git update-index --refresh
git diff-index --exit-code -p HEAD
frontend:
name: Validate, test and build frontend
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '2' # for comparison
- name: Gather branch information
id: branch_info
continue-on-error: true
run: |
branch_name=${GITHUB_REF##*/}
short_sha=${GITHUB_SHA:0:7}
echo "branch_name=${branch_name}" >> $GITHUB_OUTPUT
echo "short_sha=${short_sha}" >> $GITHUB_OUTPUT
echo "We're running on ${branch_name} (${short_sha})"
echo "REACT_APP_VERSION=${branch_name}-${short_sha}" >> $GITHUB_ENV
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
echo "REACT_APP_BACKEND_BASE_PATH=https://api.muenster-update.de" >> $GITHUB_ENV
else
echo "REACT_APP_BACKEND_BASE_PATH=https://api.staging.muenster-update.de" >> $GITHUB_ENV
fi
- name: Install Node.js 14
uses: actions/setup-node@v3
with:
node-version: 14
cache: 'npm'
cache-dependency-path: 'frontend/package-lock.json'
- name: Run 'npm ci' to install frontend dependencies
run: |
npm ci
- name: Check frontend code style
run: |
npm run lint
- name: Run frontend tests
run: |
npm run test
- name: Build frontend
run: |
echo "Executing npm run build with env REACT_APP_VERSION='$REACT_APP_VERSION' and REACT_APP_BACKEND_BASE_PATH='$REACT_APP_BACKEND_BASE_PATH'"
npm run build
- name: Precompress static files
run: |
find build \
-type f -regextype posix-extended \
-size +512c \
-iregex '.*\.(css|csv|html?|js|svg|txt|xml|json|webmanifest|ttf)' \
-exec gzip -9 -k '{}' \;
- name: Build and push frontend container image
uses: bCyberGmbH/build-container-image-action@main
with:
registry_name: docker.io
registry_username: ${{ secrets.DOCKER_HUB_USER }}
registry_password: ${{ secrets.DOCKER_HUB_PASS }}
image_repository: codeformuenster/muenster-jetzt-frontend
dockerfile_path: frontend/deployment/Dockerfile.prod
build_context: frontend
push_to_registry: ${{ github.event_name != 'pull_request' }}