Skip to content

Commit

Permalink
feat(deployment): sha images (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
theosanderson authored Dec 1, 2023
1 parent 85de79d commit f6e689a
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 20 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,27 @@ jobs:
tags: |
type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=sha,prefix=commit-
- name: Extract Docker Tags
id: extractTag
run: |
FIRST_TAG=$(echo "${{ steps.dockerMetadata.outputs.tags }}" | head -n 1)
echo "::set-output name=firstTag::$FIRST_TAG"
SECOND_TAG=$(echo "${{ steps.dockerMetadata.outputs.tags }}" | head -n 2 | tail -n 1)
echo "::set-output name=secondTag::$SECOND_TAG"
- name: Build Docker Image For Branch
uses: gradle/gradle-build-action@v2
env:
USER: ${{ github.actor }}
TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
arguments: bootBuildImage --imageName=${{ steps.dockerMetadata.outputs.tags }}
arguments: bootBuildImage --imageName=${{steps.extractTag.outputs.firstTag }}
build-root-directory: ./backend

- name: Push Docker Image For Branch
run: docker push ${{ steps.dockerMetadata.outputs.tags }}


- name: Tag With SHA tag
run: docker tag ${{ steps.extractTag.outputs.firstTag }} ${{ steps.extractTag.outputs.secondTag }}
- name: Push 1st Docker Image
run: docker push ${{ steps.extractTag.outputs.firstTag }}
- name: Push 2nd Docker Image
run: docker push ${{ steps.extractTag.outputs.secondTag }}
1 change: 1 addition & 0 deletions .github/workflows/dummyPreprocessing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
tags: |
type=ref,event=branch
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=sha,prefix=commit-
- name: Build and push image
uses: docker/build-push-action@v5
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/preprocessing-nextclade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
tags: |
type=ref,event=branch
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=sha,prefix=commit-
- name: Build and push image
uses: docker/build-push-action@v5
with:
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/update-argocd-metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Update argocd_metadata

on:
push:
branches:
- main

jobs:
update:
permissions:
packages: read
contents: read
checks: read
runs-on: ubuntu-latest

steps:
- name: Checkout Main Repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Get SHA - length 7
id: get_sha
run: |
echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
- name: Wait for Backend Docker Image
uses: lewagon/wait-on-check-action@v1.3.1
with:
ref: ${{ github.ref }}
check-name: Build Backend Docker Image
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Wait for Website Docker Image
uses: lewagon/wait-on-check-action@v1.3.1
with:
ref: ${{ github.ref }}
check-name: Build Website Docker Image
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout External Repository
uses: actions/checkout@v3
with:
repository: 'pathoplexus/argocd_metadata' # Replace with the correct repository path
token: ${{ secrets.ARGOCD_METADATA_PAT }} # Personal Access Token with appropriate permissions

- name: Modify config.json
run: |
echo '{
"branch" : "main",
"number" : 999,
"head_short_sha_7": "${{ steps.get_sha.outputs.sha }}"
}' > config.json
- name: Commit and Push Changes
run: |
git config --global user.name 'Pathoplexus bot'
git config --global user.email 'bot@pathoplexus.org'
git add config.json
git commit -m "Update config.json"
git push
1 change: 1 addition & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
images: ${{ env.DOCKER_IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha,prefix=commit-
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
- name: Build and push image
uses: docker/build-push-action@v5
Expand Down
18 changes: 7 additions & 11 deletions kubernetes/appset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@ spec:
key: token
secretName: github-access-token
requeueAfterSeconds: 60
- list:
elements:
- branch: main
number: 1
- git:
repoURL: https://github.com/pathoplexus/argocd_metadata.git
revision: HEAD
files:
- path: "config.json"
template:
metadata:
name: 'pp-{{ (printf "%.25s" .branch) | replace "_" "-" | trimSuffix "-" }}-{{.number}}'
annotations:
argocd-image-updater.argoproj.io/image-list: 'backend=ghcr.io/pathoplexus/backend:{{.branch}} website=ghcr.io/pathoplexus/website:{{.branch}}'
argocd-image-updater.argoproj.io/website.update-strategy: "digest"
argocd-image-updater.argoproj.io/backend.update-strategy: "digest"
argocd-image-updater.argoproj.io/website.pull-secret: "pullsecret:argocd/ghcr-secret"
argocd-image-updater.argoproj.io/backend.pull-secret: "pullsecret:argocd/ghcr-secret"


spec:
destination:
Expand All @@ -47,6 +41,8 @@ spec:
value: 'preview-{{ (printf "%.25s" .branch) | replace "_" "-" | trimSuffix "-" }}'
- name: shortbranch
value: '{{ (printf "%.25s" .branch) | replace "_" "-" | trimSuffix "-" }}'
- name: sha
value: '{{.head_short_sha_7}}'
- name: branch
value: '{{.branch}}'
- name: host
Expand Down
8 changes: 6 additions & 2 deletions kubernetes/preview/templates/_pathoplexus-docker-tag.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{- define "pathoplexus.dockerTag" }}
{{- $dockerTag := (eq (. | default "main") "main") | ternary "latest" . -}}
{{- if .sha }}
{{- printf "commit-%s" .sha }}
{{- else }}
{{- $dockerTag := (eq (.branch | default "main") "main") | ternary "latest" .branch -}}
{{- regexReplaceAll "/" $dockerTag "-" }}
{{- end }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion kubernetes/preview/templates/pathoplexus-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $dockerTag := include "pathoplexus.dockerTag" .Values.branch }}
{{- $dockerTag := include "pathoplexus.dockerTag" .Values }}
---
apiVersion: apps/v1
kind: Deployment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ $dockerTag := include "pathoplexus.dockerTag" .Values.branch }}
{{- $dockerTag := include "pathoplexus.dockerTag" .Values }}
{{ $configFile := .Files.Get "config.yaml" | fromYaml }}
{{ $namespace := .Values.namespace }}
{{ $backendHost := .Values.disableBackend | ternary
Expand Down

0 comments on commit f6e689a

Please sign in to comment.