Merge pull request #279 from razeware/WEB-7274 #332
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 and publish docker images | |
on: | |
push: | |
# Publish `master` as Docker `latest` image. | |
branches: | |
- master | |
- development | |
# Publish `v1.2.3` tags as releases. | |
tags: | |
- v* | |
env: | |
IMAGE_NAME: robles | |
jobs: | |
# Run tests. | |
# See also https://docs.docker.com/docker-hub/builds/automated-testing/ | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run tests | |
run: | | |
if [ -f docker-compose.test.yml ]; then | |
docker-compose --file docker-compose.test.yml build | |
docker-compose --file docker-compose.test.yml run sut | |
else | |
docker build . --file Dockerfile | |
fi | |
- name: Notify slack - test results | |
uses: voxmedia/github-action-slack-notify-build@v1 | |
if: failure() | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
with: | |
channel: circleci | |
status: FAILED | |
color: danger | |
# Push image to DockerHub. | |
push: | |
# Ensure test job passes before pushing image. | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
steps: | |
- name: Notify slack - build starting | |
uses: voxmedia/github-action-slack-notify-build@v1 | |
if: success() | |
id: slack | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
with: | |
channel: build | |
status: STARTING | |
color: warning | |
- uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/[email protected] | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/[email protected] | |
with: | |
buildkitd-flags: --debug | |
- name: Log in to DockerHub registry | |
run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u razewareci --password-stdin | |
- name: Generate tag list | |
id: generate_tags | |
run: | | |
IMAGE_ID=razeware/$IMAGE_NAME | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
# Strip git ref prefix from version | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Prefix tags with 'release' | |
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then | |
TAGS=$(echo "${VERSION}" | sed -E "s/v?([0-9]+)\.([0-9]+)\.([0-9]+)/release-v\1.\2.\3 release-v\1.\2 release-v\1/g") | |
fi | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "master" ] && TAGS=latest | |
[ "$VERSION" == "development" ] && TAGS=staging | |
echo IMAGE_ID=$IMAGE_ID | |
echo TAGS=$TAGS | |
TAG_LIST="" | |
for TAG in ${TAGS}; do | |
TAG_LIST="${TAG_LIST}${IMAGE_ID}:${TAG}," | |
done | |
echo $TAG_LIST | |
echo "::set-output name=tag_list::${TAG_LIST}" | |
- name: Build and push | |
uses: docker/[email protected] | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.generate_tags.outputs.tag_list }} | |
- name: Logout of DockerHub Registry | |
if: ${{ always() }} | |
run: docker logout | |
- name: Notify slack - build result successful | |
uses: voxmedia/github-action-slack-notify-build@v1 | |
if: success() | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
with: | |
message_id: ${{ steps.slack.outputs.message_id }} | |
channel: build | |
status: SUCCESS | |
color: good | |
- name: Notify slack - build result failed | |
uses: voxmedia/github-action-slack-notify-build@v1 | |
if: failure() | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
with: | |
message_id: ${{ steps.slack.outputs.message_id }} | |
channel: build | |
status: FAILED | |
color: danger |