Skip to content

Commit

Permalink
use reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyd3d committed Oct 14, 2024
1 parent 88fa1da commit bbede54
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 42 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Argo Deploy 🚀

on:
workflow_call:
inputs:
namespace:
description: "The Kubernetes namespace to deploy to"
required: true
type: string
image:
description: "Docker image with tag to update in values file"
required: true
type: string
secrets:
GH_TOKEN:
description: "GitHub Token for accessing private repos"
required: true

jobs:
argo-deploy:
name: Deploy 🚀
runs-on: ubuntu-latest

steps:
- name: Checkout code from another repository
uses: actions/checkout@v4
with:
repository: kennyd3d/argo-deployments
path: ./argo-deployments
token: ${{ secrets.GH_TOKEN }}

- name: Force update local branch with remote
working-directory: ./argo-deployments
run: |
git fetch origin main
git reset --hard origin/main
git clean -fd
- name: Update image tag in values.yaml
working-directory: ./argo-deployments
run: |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq &&\
sudo chmod +x /usr/bin/yq
yq e -i '.environments.${{ inputs.namespace }}.image = "${{ inputs.image }}"' ./hello-world-app/values-${{ inputs.namespace }}.yaml
- name: Commit files
working-directory: ./argo-deployments
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "[BOT] Update k8 deployment" || echo "No changes to commit"
- name: Pull the latest changes from main
working-directory: ./argo-deployments
run: |
git pull origin main --rebase
- name: Push changes
working-directory: ./argo-deployments
run: |
git push origin main --force-with-lease
49 changes: 7 additions & 42 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,11 @@ jobs:
kennyd3d/hello-world-app:${{ steps.prepare.outputs.sha_short }}
kennyd3d/hello-world-app:dev
argo-deploy:
name: Deploy 🚀
runs-on: ubuntu-latest
deploy:
needs: build
steps:
- name: Checkout code from another repository
uses: actions/checkout@v4
with:
repository: kennyd3d/argo-deployments
path: ./argo-deployments
token: ${{ secrets.GH_TOKEN }} # PAT for private repos

- name: Force update local branch with remote
working-directory: ./argo-deployments
run: |
git fetch origin main
git reset --hard origin/main
git clean -fd
- name: Update image tag in values-dev.yaml
working-directory: ./argo-deployments
run: |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq &&\
sudo chmod +x /usr/bin/yq
yq e -i '.environments.dev.image = "kennyd3d/hello-world-app:${{ needs.build.outputs.sha_short }}"' ./hello-world-app/values-dev.yaml
- name: Commit files
working-directory: ./argo-deployments
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "[BOT] Update k8 deployment" || echo "No changes to commit"
- name: Pull the latest changes from main
working-directory: ./argo-deployments
run: |
git pull origin main --rebase
- name: Push changes
working-directory: ./argo-deployments
run: |
git push origin main --force-with-lease
uses: kennyd3d/argo-demo/.github/workflows/deploy.yml
with:
namespace: "dev"
image: "kennyd3d/hello-world-app:${{ needs.build.outputs.sha_short }}"
secrets:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

0 comments on commit bbede54

Please sign in to comment.