This repository has been archived by the owner on Feb 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy images using CI and GHCR.IO
- Loading branch information
Showing
1 changed file
with
33 additions
and
58 deletions.
There are no files selected for viewing
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
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 |