Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Commit

Permalink
Update docker-build-push.yml
Browse files Browse the repository at this point in the history
Deploy images using CI and GHCR.IO
  • Loading branch information
dfuchss authored Nov 22, 2024
1 parent 2c31328 commit 1d1edd8
Showing 1 changed file with 33 additions and 58 deletions.
91 changes: 33 additions & 58 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -1,80 +1,55 @@
name: CI
name: Docker CI

on:
push:
branches: [ "main" ]
paths-ignore:
- '**.md'
- 'deployment'
pull_request:
branches: [ "main" ]
paths-ignore:
- '**.md'
- 'deployment'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build-tutor-assistant:
build:
name: "Docker Build and/or Deploy"
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}

permissions:
contents: read
packages: write

strategy:
matrix:
image: [ "tutor-assistant", "tutor-assistant-app-service", "tutor-assistant-web" ]

steps:
- uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image
run: docker build ${{ matrix.image }} --file ${{ matrix.image }}/Dockerfile --tag ${{ matrix.image }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: tutor-assistant
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/tutor-assistant:latest
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/tutor-assistant:latest
cache-to: type=inline

build-tutor-assistant-app-service:
runs-on: ubuntu-latest
- name: Log into Registry
if: ${{ github.event_name == 'push' }}
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin

steps:
- uses: actions/checkout@v4
- name: Push Image
if: ${{ github.event_name == 'push' }}
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
- name: Build and push
uses: docker/build-push-action@v6
with:
context: tutor-assistant-app-service
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/tutor-assistant-app-service:latest
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/tutor-assistant-app-service:latest
cache-to: type=inline
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
build-tutor-assistant-web:
runs-on: ubuntu-latest
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
steps:
- uses: actions/checkout@v4
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
- name: Build and push
uses: docker/build-push-action@v6
with:
context: tutor-assistent-web
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/tutor-assistant-web:latest
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/tutor-assistant-web:latest
cache-to: type=inline
docker tag ${{ matrix.image }} $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION

0 comments on commit 1d1edd8

Please sign in to comment.