Skip to content

Commit

Permalink
add docker build step
Browse files Browse the repository at this point in the history
  • Loading branch information
egekocabas committed Nov 29, 2024
1 parent 60373e0 commit a8117d8
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
129 changes: 129 additions & 0 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Build Docker Image

on:
workflow_call:
outputs:
client_image_tag:
description: "The tag of the client image that was built"
value: ${{ jobs.build.outputs.client_image_tag }}
application_server_image_tag:
description: "The tag of the application server image that was built"
value: ${{ jobs.build.outputs.application_server_image_tag }}
webhook_listener_image_tag:
description: "The tag of the webhook listener image that was built"
value: ${{ jobs.build.outputs.webhook_listener_image_tag }}


jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./client/Dockerfile
image: ghcr.io/ls1intum/helios/client
context: ./client
path: client
- dockerfile: ./server/application-server/Dockerfile
image: ghcr.io/ls1intum/helios/application-server
context: ./server/application-server
path: server
- dockerfile: ./server/webhook-listener/Dockerfile
image: ghcr.io/ls1intum/helios/webhook-listener
context: ./server/webhook-listener
path: webhook-listener
outputs:
client_image_tag: "${{ steps.output-tag-client.outputs.client_image_tag }}"
application_server_image_tag: "${{ steps.output-tag-server.outputs.application_server_image_tag }}"
webhook_listener_image_tag: "${{ steps.output-tag-webhook-listener.outputs.webhook_listener_image_tag }}"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Get changed files in the client folder
id: changed-files-client-folder
uses: tj-actions/changed-files@v45
with:
files: client/**

- name: Get changed files in the application server folder
id: changed-files-application-server-folder
uses: tj-actions/changed-files@v45
with:
files: server/application-server/**

- name: Get changed files in the webhook listener folder
id: changed-files-webhook-listener-folder
uses: tj-actions/changed-files@v45
with:
files: server/webhook-listener/**

- name: Log in to the Container registry
if: ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true') || (steps.changed-files-application-server-folder.outputs.any_changed == 'true') || (steps.changed-files-webhook-listener-folder.outputs.any_changed == 'true') }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
if: ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true') || (steps.changed-files-application-server-folder.outputs.any_changed == 'true') || (steps.changed-files-webhook-listener-folder.outputs.any_changed == 'true') }}
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Install Docker Buildx
if: ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true') || (steps.changed-files-application-server-folder.outputs.any_changed == 'true') || (steps.changed-files-webhook-listener-folder.outputs.any_changed == 'true') }}
id: buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.image }}
tags: |
# Apply 'latest' tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
# Apply 'latest' tag for a specific branch (e.g., staging)
# TODO: remove below
type=raw,value=latest,enable=${{ github.ref_name == '66-setup-helios-deployment' }}
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker Image
uses: docker/build-push-action@v6
if: ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true' && matrix.path == 'client') || (steps.changed-files-application-server-folder.outputs.any_changed == 'true' && matrix.path == 'server') || (steps.changed-files-webhook-listener-folder.outputs.any_changed == 'true' && matrix.path == 'webhook-listener') }}
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}

- id: output-tag-client
run: |
if [[ "${{ matrix.path }}" == "client" ]] && [[ "${{ steps.changed-files-client-folder.outputs.any_changed }}" == "true" ]]; then
echo "client_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.path }}" == "client" ]]; then
echo "client_image_tag=latest" >> "$GITHUB_OUTPUT"
fi
- id: output-tag-application-server
run: |
if [[ "${{ matrix.path }}" == "server" ]] && [[ "${{ steps.changed-files-application-server-folder.outputs.any_changed }}" == "true" ]]; then
echo "application_server_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.path }}" == "server" ]]; then
echo "application_server_image_tag=latest" >> "$GITHUB_OUTPUT"
fi
- id: output-tag-webhook-listener
run: |
if [[ "${{ matrix.path }}" == "webhook-listener" ]] && [[ "${{ steps.changed-files-webhook-listener-folder.outputs.any_changed }}" == "true" ]]; then
echo "webhook_listener_image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.path }}" == "webhook-listener" ]]; then
echo "webhook_listener_image_tag=latest" >> "$GITHUB_OUTPUT"
fi
24 changes: 24 additions & 0 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build and Deploy to Prod

on:
push:
branches:
- main
# TODO: remove below
- 66-setup-helios-deployment

jobs:
build-prod-container:
uses: ./.github/workflows/build_docker.yml
secrets: inherit
# deploy-prod-container:
# needs:
# - run-tests
# - build-prod-container
# uses: ./.github/workflows/deploy_docker.yml
# secrets: inherit
with:
environment: production
client_image_tag: "${{ needs.build-prod-container.outputs.client_image_tag }}"
application_server_image_tag: "${{ needs.build-prod-container.outputs.application_server_image_tag }}"
webhook_listener_image_tag: "${{ needs.build-prod-container.outputs.webhook_listener_image_tag }}"

0 comments on commit a8117d8

Please sign in to comment.