test: gitops staging test #111
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: GitOps | |
on: | |
push: | |
branches: | |
- main | |
- staging | |
paths: | |
- services/** | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
changes: | |
runs-on: ubuntu-latest | |
outputs: | |
services: ${{ steps.filter.outputs.changes }} | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Filter file changes | |
id: filter | |
uses: dorny/paths-filter@v3 | |
with: | |
base: ${{ github.ref }} | |
filters: | | |
web: | |
- 'services/web/**' | |
account: | |
- 'services/account/**' | |
item: | |
- 'services/item/**' | |
wishlist: | |
- 'services/wishlist/**' | |
transaction: | |
- 'services/transaction/**' | |
notification: | |
- 'services/notification/**' | |
rabbitmq: | |
- 'services/rabbitmq/**' | |
build: | |
name: Build and push Docker image | |
runs-on: ubuntu-latest | |
needs: changes | |
strategy: | |
matrix: | |
service: ${{ fromJson(needs.changes.outputs.services) }} | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./services/${{ matrix.service }} | |
push: true | |
tags: | | |
z1yoon/nshm-${{ matrix.service }}:$GITHUB_REF_NAME-${{ matrix.service }}-${{ github.sha }} | |
z1yoon/nshm-${{ matrix.service }}:$GITHUB_REF_NAME | |
build-args: | | |
NEXT_PUBLIC_API_BASE_URL=${{ secrets.NEXT_PUBLIC_API_BASE_URL }} | |
update: | |
name: Update Helm Manifests | |
runs-on: ubuntu-latest | |
container: | |
image: argoproj/argocd | |
needs: changes | |
strategy: | |
matrix: | |
service: ${{ fromJson(needs.changes.outputs.services) }} | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Update Image Tag Values | |
run: | | |
echo "chart_dir=helm/nshm" >> $GITHUB_ENV | |
echo $chart_dir | |
new_image_tag=${{ matrix.service }}-${{ github.sha }} | |
sed -i "/z1yoon\/nshm-${{ matrix.service }}/{n;s/tag: .*/tag: $new_image_tag/;}" $chart_dir/$GITHUB_REF_NAME-values.yaml | |
cat $chart_dir/$GITHUB_REF_NAME-values.yaml | |
- name: Apply Changes with ArgoCD CLI | |
run: | | |
argocd app set nshm-$GITHUB_REF_NAME \ | |
--values $chart_dir/$GITHUB_REF_NAME-values.yaml \ | |
--repo https://github.com/SE-Row-1/nus-secondhand-market.git \ | |
--revision $GITHUB_REF_NAME \ | |
--async | |
env: | |
ARGOCD_SERVER: argocd.nshm.store | |
ARGOCD_AUTH_TOKEN: ${{ secrets.ARGOCD_TOKEN }} | |
sync: | |
name: Sync ArgoCD Application | |
runs-on: ubuntu-latest | |
container: | |
image: argoproj/argocd | |
needs: update | |
steps: | |
- name: Sync ArgoCD Application | |
if: github.ref == 'refs/heads/staging' || (github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch') | |
run: | | |
argocd app sync nshm-${{ github.ref_name }} | |
env: | |
ARGOCD_SERVER: argocd.nshm.store | |
ARGOCD_AUTH_TOKEN: ${{ secrets.ARGOCD_TOKEN }} |