Merge pull request #315 from lardbit/delay-if-not-released #423
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: nefarious ci/cd | |
on: | |
push: | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
# https://github.com/docker/setup-qemu-action | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
# https://github.com/docker/setup-buildx-action | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Set tag name | |
id: tag_name | |
shell: bash | |
run: | | |
# get and sanitize the branch name | |
branch=${GITHUB_REF#refs/heads/} | |
branch=${branch//\//-} | |
# derive the docker image tag name from the git branch name | |
if [[ $branch == 'master' ]]; then | |
tag='latest' | |
else | |
tag="$branch" | |
fi | |
echo "##[set-output name=tag;]$(echo ${tag})" | |
- name: Build front-end image | |
run: | | |
set -e | |
# get tag name | |
tag=${{ steps.tag_name.outputs.tag }} | |
# build front-end app | |
docker build -t lardbit/nefarious:frontend-$tag -f Dockerfile-frontend . | |
# push front-end image | |
docker push lardbit/nefarious:frontend-$tag | |
- name: Build and Run tests | |
run: | | |
set -e | |
# get tag name | |
tag=${{ steps.tag_name.outputs.tag }} | |
# echo images | |
docker images | |
# build back-end app | |
docker build --build-arg tag=$tag -t lardbit/nefarious:$tag . | |
# create docker network to link containers | |
docker network create tests | |
# run redis | |
docker run --network tests --name redis --rm -d redis | |
# run unit tests | |
docker run --network tests -e REDIS_HOST=redis --entrypoint /env/bin/python lardbit/nefarious:$tag manage.py test | |
- name: Build multi-arch images and push to registry | |
run: | | |
set -e | |
# get tag name | |
tag=${{ steps.tag_name.outputs.tag }} | |
# store git commit in image for version identification | |
echo "$GITHUB_SHA" > src/.commit | |
# build image (cache result) | |
docker buildx build \ | |
--platform linux/amd64,linux/arm64 \ | |
--output "type=image,push=false" \ | |
--cache-to "type=local,dest=/tmp/.buildx-cache" \ | |
--build-arg tag=$tag \ | |
--tag lardbit/nefarious:${tag} \ | |
--file Dockerfile . | |
# push image (from cached result) | |
docker buildx build \ | |
--platform linux/amd64,linux/arm64 \ | |
--output "type=image,push=true" \ | |
--cache-from "type=local,src=/tmp/.buildx-cache" \ | |
--build-arg tag=$tag \ | |
--tag lardbit/nefarious:${tag} \ | |
--file Dockerfile . |