Skip to content

MNTOR-2247: CICD

MNTOR-2247: CICD #12

name: Build Docker image and publish
on:
push:
branches: [ main, MNTOR-2247 ]
tags: '*'
pull_request:
branches: [ main ]
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: mozilla/blurts-server
tags: |
type=semver,pattern={{raw}}
type=raw,value=cicd-{{sha}},event=tag
# - name: Build and push Docker image
# uses: docker/build-push-action@v5
# with:
# context: .
# file: ./Dockerfile
# push: true
# tags: ${{ steps.meta.outputs.tags }}
- name: Create version.json
run: |
echo "{\"commit\":\"$GITHUB_SHA\",\"version\":\"$GITHUB_REF\",\"source\":\"https://github.com/$GITHUB_REPOSITORY\",\"build\":\"$GITHUB_RUN_ID\"}" > version.json
- name: Build Docker image
run: |
docker build --tag blurts-server \
--build-arg SENTRY_RELEASE="$GITHUB_REF" \
.
- name: Deploy to Dockerhub
run: |
echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
# deploy main
docker tag blurts-server ${{ env.DOCKERHUB_REPO }}:latest
docker push ${{ env.DOCKERHUB_REPO }}:latest
elif [ "${{ github.ref }}" == "refs/tags/"* ]; then
# deploy a release tag
echo "${{ env.DOCKERHUB_REPO }}:${{ github.ref }}"
docker tag blurts-server "${{ env.DOCKERHUB_REPO }}:${{ github.ref }}"
docker images
docker push "${{ env.DOCKERHUB_REPO }}:${{ github.ref }}"
fi