Publish Docker Images #235
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: Publish Docker Images | |
on: | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: '38 6 * * TUE' | |
jobs: | |
publish_docker_image: | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: main | |
- name: Generate image tag name | |
# docker compose will tag the build of docker/Dockerfile with the value | |
# of $SPACEFINDER_WEB_IMAGE, allowing us to reference it. | |
# Appending envar definitions to GITHUB_ENV makes them available to | |
# subsequent steps. | |
run: | | |
BUILD_UUID="$(uuidgen)" | |
GIT_ID="$(git rev-parse --short HEAD)" | |
DATE_ID="$(date --iso-8601=date)" | |
IMAGE_BASE="registry.gitlab.developers.cam.ac.uk/lib/dev/spacefinder/spacefinder" | |
IMAGE_EXACT="${IMAGE_BASE:?}:${BUILD_UUID:?}" | |
cat >> "${GITHUB_ENV:?}" <<EOF | |
IMAGE_EXACT=${IMAGE_EXACT:?} | |
IMAGE_DATE_GIT=${IMAGE_BASE:?}:date.${DATE_ID:?}_git.${GIT_ID:?} | |
IMAGE_DATE=${IMAGE_BASE:?}:date.${DATE_ID:?} | |
IMAGE_LATEST=${IMAGE_BASE:?}:latest | |
SPACEFINDER_WEB_IMAGE=${IMAGE_EXACT:?} | |
EOF | |
- name: Sanity check image tags | |
run: | | |
cat <<EOF | |
IMAGE_EXACT="${IMAGE_EXACT:?}" | |
IMAGE_DATE_GIT="${IMAGE_DATE_GIT:?}" | |
IMAGE_DATE="${IMAGE_DATE:?}" | |
IMAGE_LATEST="${IMAGE_LATEST:?}" | |
SPACEFINDER_WEB_IMAGE="${SPACEFINDER_WEB_IMAGE:?}" | |
EOF | |
# Smoke test | |
- name: Build app image | |
run: | | |
echo SPACEFINDER_WEB_IMAGE="${SPACEFINDER_WEB_IMAGE:?}" | |
docker compose -f docker/docker-compose.yml build web | |
- name: Run app and verify /health_check is successful | |
run: | | |
docker compose \ | |
-f docker/docker-compose.yml -f docker/docker-compose.test.yml \ | |
up --abort-on-container-exit | |
- name: Login to container registry | |
uses: docker/login-action@v1 | |
with: | |
registry: registry.gitlab.developers.cam.ac.uk | |
username: ${{ secrets.GITLAB_REGISTRY_TOKEN_USERNAME }} | |
password: ${{ secrets.GITLAB_REGISTRY_TOKEN }} | |
- name: Publish image | |
run: | | |
for tag in "${IMAGE_DATE_GIT:?}" "${IMAGE_DATE:?}" "${IMAGE_LATEST:?}"; do | |
docker image tag "${IMAGE_EXACT:?}" "$tag" | |
docker image push "$tag" | |
done |