Skip to content

Commit

Permalink
Debug improved Github actions file (#59)
Browse files Browse the repository at this point in the history
* Add new dependency between workflows

* Split client and server image tag

* Fix bash syntax error

* Make production ready

* Add latest tag to production
  • Loading branch information
robertjndw authored Jul 19, 2023
1 parent 7e79d12 commit 9efee1d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 54 deletions.
65 changes: 39 additions & 26 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ name: Build Docker Image

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

jobs:
build:
Expand All @@ -19,8 +26,28 @@ jobs:
context: ./server
path: server
outputs:
image_tag: ${{ steps.output-tag.outputs.image_tag }}
server_image_tag: "${{ steps.output-tag.outputs.image_tag }}"
client_image_tag: "${{ steps.output-tag.outputs.image_tag }}"
steps:
- name: Compute Tag
uses: actions/github-script@v6
id: compute-tag
with:
result-encoding: string
script: |
if (context.eventName === "pull_request") {
return "pr-" + context.issue.number;
}
if (context.eventName === "push") {
if (context.ref.startsWith("refs/tags/")) {
return context.ref.slice(10);
}
if (context.ref === "refs/heads/develop") {
return "develop";
}
}
return "latest";
- name: Checkout
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -57,40 +84,26 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v2

- name: Compute Tag
uses: actions/github-script@v6
id: compute-tag
with:
result-encoding: string
script: |
if (context.eventName === "pull_request") {
return "pr-" + context.issue.number;
}
if (context.eventName === "push") {
if (context.ref.startsWith("refs/tags/")) {
return context.ref.slice(10);
}
if (context.ref === "refs/heads/develop") {
return "develop";
}
}
return "latest";
- id: output-tag
run: echo "image_tag=${{ steps.compute-tag.outputs.result }}" >> "$GITHUB_OUTPUT"

- name: Build and push Docker Image
uses: docker/build-push-action@v4
if: ${{ (steps.changed-files-client-folder.outputs.any_changed == 'true' && matrix.path == 'client') || (steps.changed-files-server-folder.outputs.any_changed == 'true' && matrix.path == 'server') }}
env:
IMAGE_TAG: ${{ steps.compute-tag.outputs.result }}
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ matrix.image }}:${{ env.IMAGE_TAG }}
tags: ${{ matrix.image }}:${{ steps.compute-tag.outputs.result }}
build-args: |
"SERVER_HOST=${{ vars.SERVER_HOST }}"
"KEYCLOAK_HOST=${{ vars.KEYCLOAK_HOST }}"
"KEYCLOAK_REALM_NAME=${{ vars.KEYCLOAK_REALM_NAME }}"
- id: output-tag
run: |
if [[ "${{ matrix.path }}" == "client" ]] && [[ "${{ steps.changed-files-client-folder.outputs.any_changed }}" == "true" ]]; then
echo "image_tag=${{ steps.compute-tag.outputs.result }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.path }}" == "server" ]] && [[ "${{ steps.changed-files-server-folder.outputs.any_changed }}" == "true" ]]; then
echo "image_tag=${{ steps.compute-tag.outputs.result }}" >> "$GITHUB_OUTPUT"
else
echo "image_tag=latest" >> "$GITHUB_OUTPUT"
fi
39 changes: 14 additions & 25 deletions .github/workflows/deploy_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ on:
environment:
required: true
type: string
server_image_tag:
required: true
type: string
client_image_tag:
required: true
type: string

jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Use Computed Server Tag
run: echo "The computed server tag is ${{ inputs.server_image_tag }}"

- name: Use Computed Client Tag
run: echo "The computed client tag is ${{ inputs.client_image_tag }}"

- name: SSH to VM and Execute Docker-Compose Down
uses: appleboy/[email protected]
with:
Expand Down Expand Up @@ -72,32 +84,8 @@ jobs:
source: "master.cf"
target: /home/${{ vars.VM_USERNAME }}/postfix-config/

- name: Compute Tag
uses: actions/github-script@v6
id: compute-tag
with:
result-encoding: string
script: |
if (context.eventName === "pull_request") {
return "pr-" + context.issue.number;
}
if (context.eventName === "push") {
if (context.ref.startsWith("refs/tags/")) {
return context.ref.slice(10);
}
if (context.ref === "refs/heads/develop") {
return "develop";
}
}
return "latest";
- id: output-tag
run: echo "image_tag=${{ steps.compute-tag.outputs.result }}" >> "$GITHUB_OUTPUT"

- name: SSH to VM and create .env.prod file
uses: appleboy/[email protected]
env:
IMAGE_TAG: ${{ steps.compute-tag.outputs.result }}
with:
host: ${{ vars.VM_HOST }}
username: ${{ vars.VM_USERNAME }}
Expand Down Expand Up @@ -128,7 +116,8 @@ jobs:
echo "KEYCLOAK_CLIENT_SECRET=${{ secrets.KEYCLOAK_CLIENT_SECRET }}" >> .env.prod
echo "IOS_SENDER_MAIL=${{ vars.IOS_SENDER_MAIL }}" >> .env.prod
echo "IMAGE_TAG=${{ env.IMAGE_TAG }}" >> .env.prod
echo "SERVER_IMAGE_TAG=${{ inputs.server_image_tag }}" >> .env.prod
echo "CLIENT_IMAGE_TAG=${{ inputs.client_image_tag }}" >> .env.prod
- name: SSH to VM and Execute Docker-Compose Up
uses: appleboy/[email protected]
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ jobs:
secrets: inherit
with:
environment: Dev

server_image_tag: "${{ needs.build-dev-container.outputs.server_image_tag }}"
client_image_tag: "${{ needs.build-dev-container.outputs.client_image_tag }}"
2 changes: 2 additions & 0 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ jobs:
secrets: inherit
with:
environment: Production
server_image_tag: "latest"
client_image_tag: "latest"

4 changes: 2 additions & 2 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
- ./letsencrypt:/letsencrypt

server:
image: "ghcr.io/ls1intum/prompt/prompt-server:${IMAGE_TAG}"
image: "ghcr.io/ls1intum/prompt/prompt-server:${SERVER_IMAGE_TAG}"
container_name: orgatool-server
labels:
- "traefik.enable=true"
Expand Down Expand Up @@ -72,7 +72,7 @@ services:
retries: 5

client:
image: "ghcr.io/ls1intum/prompt/prompt-client:${IMAGE_TAG}"
image: "ghcr.io/ls1intum/prompt/prompt-client:${CLIENT_IMAGE_TAG}"
container_name: orgatool-client
environment:
- TZ=Europe/Berlin
Expand Down

0 comments on commit 9efee1d

Please sign in to comment.