Skip to content

test: gitops staging test #112

test: gitops staging test

test: gitops staging test #112

Workflow file for this run

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-and-sync:
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: Login to ArgoCD
run: |
argocd login argocd.nshm.store \
--username admin \
--password ${{ secrets.ARGOCD_PASSWORD }} \
--insecure
- 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
- 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 }}