Docker #7196
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: Docker | |
on: | |
pull_request: | |
workflow_dispatch: | |
# Runs from default branch, which is develop | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
meta: | |
runs-on: ubuntu-latest | |
outputs: | |
labels: ${{ steps.metadata.outputs.labels }} | |
steps: | |
- id: metadata | |
uses: crazy-max/ghaction-docker-meta@v5 | |
with: | |
images: fdmmonster/fdm-monster | |
docker: | |
needs: [ meta ] | |
runs-on: ubuntu-latest | |
name: "Docker build" | |
steps: | |
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Login to DockerHub with environment variables | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
if: github.event_name != 'pull_request' | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# https://stackoverflow.com/questions/57968497/how-do-i-set-an-env-var-with-a-bash-expression-in-github-actions | |
- name: get-server-version | |
# https://gist.github.com/DarrenN/8c6a5b969481725a4413?permalink_comment_id=3863317#gistcomment-3863317 | |
run: | | |
echo "SERVER_VERSION=$(npm pkg get version | sed 's/"//g')" >> $GITHUB_ENV | |
# New intended logic | |
# if branch is develop => push to dockerhub with tag 'develop' | |
# if branch is main => push to dockerhub with tag 'main' | |
- name: Tagging Strategy | |
id: tagging | |
uses: HackerHappyHour/tagging-strategy@v3 | |
with: | |
image_name: davidzwa/fdm-monster | |
tag_name: ${{ env.SERVER_VERSION }}-develop | |
tags: | | |
%X.Y.Z% | |
extra_tags: | | |
develop::${{ github.ref == 'refs/heads/develop' || github.event.pull_request.base.ref == 'develop' }} | |
- name: Tagging Strategy | |
id: tagging2 | |
uses: HackerHappyHour/tagging-strategy@v3 | |
with: | |
image_name: fdmmonster/fdm-monster | |
tag_name: ${{ env.SERVER_VERSION }}-develop | |
tags: | | |
%X.Y.Z% | |
extra_tags: | | |
develop::${{ github.ref == 'refs/heads/develop' || github.event.pull_request.base.ref == 'develop' }} | |
# Show docker tags to be (conditionally) pushed | |
- name: "Show docker tags" | |
run: | | |
echo '${{ github.ref }}' | |
echo '${{ github.ref_type }}' | |
echo '${{ github.event.pull_request.base.ref }}' | |
echo '${{ steps.tagging.outputs.tags }}' | |
# Speed up the build next time | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ hashfiles('./docker/Dockerfile') }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
# Clone the repo and build the image | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
push: ${{ github.event_name != 'pull_request' }} | |
context: "{{defaultContext}}" | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max | |
file: ./docker/Dockerfile | |
tags: ${{ steps.tagging.outputs.tags }} | |
labels: ${{ needs.meta.outputs.labels }} | |
- name: Build and push | |
id: docker_build_new | |
uses: docker/build-push-action@v5 | |
with: | |
push: ${{ github.event_name != 'pull_request' }} | |
context: "{{defaultContext}}" | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max | |
file: ./docker/Dockerfile | |
tags: ${{ steps.tagging2.outputs.tags }} | |
labels: ${{ needs.meta.outputs.labels }} | |
# Show image digest output | |
- name: Image digest | |
run: echo ${{ steps.docker_build.outputs.digest }} | |
- name: Image digest 2 | |
run: echo ${{ steps.docker_build_new.outputs.digest }} |