Build and Release mgconsole Docker Image #7
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 Release mgconsole Docker Image | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Version of the Docker image to publish." | |
required: true | |
default: "0.0.1" | |
force_release: | |
description: "Force release even if the version already exists." | |
type: boolean | |
required: false | |
default: false | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_ORGANIZATION_NAME: memgraph | |
DOCKER_REPOSITORY_NAME: mgconsole | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Check if specified version is already pushed | |
run: | | |
EXISTS=$(docker manifest inspect ${{ env.DOCKER_ORGANIZATION_NAME }}/${{ env.DOCKER_REPOSITORY_NAME }}:${{ github.event.inputs.version }} > /dev/null; echo $?) | |
echo $EXISTS | |
if [[ ${EXISTS} -eq 0 ]]; then | |
echo 'The specified version has been already released to DockerHub.' | |
if [[ ${{ github.event.inputs.force_release }} == 'true' ]]; then | |
echo 'Forcing the release!' | |
else | |
echo 'Stopping the release!' | |
exit 1 | |
fi | |
else | |
echo 'All good, the specified version has not been released to DockerHub.' | |
fi | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.DOCKER_ORGANIZATION_NAME }}/${{ env.DOCKER_REPOSITORY_NAME }}:${{ github.event.inputs.version }} | |
${{ env.DOCKER_ORGANIZATION_NAME }}/${{ env.DOCKER_REPOSITORY_NAME }}:latest | |
platforms: linux/amd64,linux/arm64 | |
- name: Verify Docker image | |
run: | | |
docker run --rm $DOCKER_ORGANIZATION_NAME/$DOCKER_REPOSITORY_NAME:${{ github.event.inputs.version }} --version |