Skip to content

Commit

Permalink
Fix CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog committed Jun 14, 2024
1 parent 8f3a6cd commit e01f118
Showing 1 changed file with 53 additions and 35 deletions.
88 changes: 53 additions & 35 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ on:
branches:
- main
workflow_dispatch:
inputs:
image_tag:
description: 'Docker image tag to deploy'
required: true
default: 'main'
environment:
description: 'Environment to deploy to'
required: true
default: 'stag'
options:
- stag
- prod
inputs:
image_tag:
description: 'Docker image tag to deploy'
required: true
default: 'main'
environment:
description: 'Environment to deploy too'
required: true
default: 'sandbox'
type: choice
options:
- sandbox
- production

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -31,9 +32,11 @@ jobs:
id: get_package_hash
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /orgs/MinBZK/packages/container/tad/versions | jq '.[] | select(.metadata.container.tags | contains(["${{ inputs.image_tag }}"])) | .name'" >> "$GITHUB_OUTPUT"
container_id=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /orgs/MinBZK/packages/container/tad/versions | jq '.[] | select(.metadata.container.tags | contains(["${{ inputs.image_tag }}"])) | .name')
echo "container_id=${{ inputs.image_tag }}@$container_id" >> "$GITHUB_OUTPUT"
else
echo "gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /orgs/MinBZK/packages/container/tad/versions | jq '.[] | select(.metadata.container.tags | contains(["main"])) | .name'" >> "$GITHUB_OUTPUT"
container_id=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /orgs/MinBZK/packages/container/tad/versions | jq '.[] | select(.metadata.container.tags | contains(["main"])) | .name')
echo "container_id=main@$container_id" >> "$GITHUB_OUTPUT"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -42,41 +45,56 @@ jobs:
id: get_deploy_env
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
if [ "${{ inputs.environment }}" == "prod" ]; then
echo "production" >> "$GITHUB_OUTPUT"
else
echo "staging" >> "$GITHUB_OUTPUT"
fi
echo "" >> "$GITHUB_OUTPUT"
echo "env=${{ inputs.environment }}" >> "$GITHUB_OUTPUT"
else
echo "staging" >> "$GITHUB_OUTPUT"
echo "env=sandbox" >> "$GITHUB_OUTPUT"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Print deploy hash and environment
run: |
echo "container: pr-33@${{ steps.get_package_hash.outputs.container_id }}"
echo "overlay: ${{ steps.get_deploy_env.outputs.env }}"
echo "Version: ${{ inputs.image_tag || 'main' }}"
echo "Actor: ${{ github.actor}}"
- name: check correct name
run: |
if [ -z "${{steps.get_package_hash.outputs}}" ]; then
if [ -z "${{steps.get_package_hash.outputs.container_id}}" ]; then
echo "Variable is empty. Failing the workflow."
exit 1
fi
- name: Print deploy hash and environment
run: |
echo ${{ steps.get_package_hash.outputs }}
echo ${{ steps.get_deploy_env.outputs }}
- uses: actions/checkout@v4
with:
repository: '${{ github.server_url }}/minbzk/ai-validation-infra'
repository: 'minbzk/ai-validation-infra'
ssh-key: ${{ secrets.DEPLOY_KEY }}
ref: main
path: ai-validation-infra

- name: Configure Git
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Make changes to the file
run: |
sed -i 's/newTag: .*$/newTag: ${{ steps.get_package_hash.outputs.container_id }}/g' apps/tad/overlays/${{ steps.get_deploy_env.outputs.env }}/kustomization.yaml
sed -i 's/commithash: .*$/commithash: ${{ steps.get_package_hash.outputs.container_id }} }/g' apps/tad/overlays/${{ steps.get_deploy_env.outputs.env }}/kustomization.yaml
sed -i 's|minbzk.github.io/version: .*$|minbzk.github.io/version: ${{ inputs.image_tag || 'main' }} }|g' apps/tad/overlays/${{ steps.get_deploy_env.outputs.env }}/kustomization.yaml
git add apps/tad/overlays/${{ steps.get_deploy_env.outputs.env }}/kustomization.yaml
git commit -m "Update tad overlays:${{ steps.get_deploy_env.outputs.env }} tag:${{ steps.get_package_hash.outputs.container_id }} actor:${{ github.actor}}"
- name: Make changes to the file
run: |
cd ai-validation-infra
sed -i 's/newTag: .*$/newTag: ${{ steps.get_package_hash.outputs }}/g' apps/tad/overlays/${{ steps.get_deploy_env.outputs }}/kustomization.yaml
git add apps/tad/overlays/${{ steps.get_deploy_env.outputs }}/kustomization.yaml
git commit -m "Update apps/tad/overlays/${{ steps.get_deploy_env.outputs }}/kustomization.yaml"
git push
- name: remove ssh key
if: always()
run: rm -f ~/.ssh/id_rsa

0 comments on commit e01f118

Please sign in to comment.