Skip to content

Commit

Permalink
build(ci): added Docker build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoM committed Jan 23, 2024
1 parent 1d16c2a commit 806e21b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Docker
# Docker workflow allows the creation and publishing of new Bondscape website Docker tags.
# This workflow is run only when a new commit is pushed to main, or a new tag is created.
on:
pull_request:
push:
branches:
- main
tags:
- v*

jobs:
Build-and-Publish:
name: Build and publish Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Login to DockerHub 👤
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Prepare tags 🏷️
id: prep
run: |
DOCKER_IMAGE=desmoslabs/mooncake-website
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:latest"
if [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Build and push 📤
uses: docker/build-push-action@v4
with:
push: false
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}

0 comments on commit 806e21b

Please sign in to comment.