|
| 1 | +name: Service CI/CD Pipeline to Release and Deploy to Dev Env |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - "apps/user/**" # Only trigger for changes in the apps/user directory |
| 9 | + |
| 10 | +jobs: |
| 11 | + release: |
| 12 | + if: | |
| 13 | + !contains(github.event.head_commit.message, 'skip-ci') |
| 14 | + name: Build and Release Docker Image |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Use Node.js 20.x |
| 20 | + uses: actions/setup-node@v3 |
| 21 | + with: |
| 22 | + node-version: "20.x" |
| 23 | + |
| 24 | + - name: Yarn Clean Install |
| 25 | + run: yarn workspace user install |
| 26 | + |
| 27 | + - name: Install Semantic Release |
| 28 | + run: yarn global add semantic-release @semantic-release/{git,exec,changelog} |
| 29 | + |
| 30 | + - name: Semantic Release |
| 31 | + run: semantic-release |
| 32 | + env: |
| 33 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + |
| 35 | + - name: Make Build |
| 36 | + run: yarn workspace user build |
| 37 | + |
| 38 | + - name: Get NPM Version |
| 39 | + id: package-version |
| 40 | + uses: martinbeentjes/npm-get-version-action@master |
| 41 | + with: |
| 42 | + path: apps/user |
| 43 | + |
| 44 | + - name: Set up QEMU |
| 45 | + uses: docker/setup-qemu-action@v3 |
| 46 | + |
| 47 | + - name: Set up Docker Buildx |
| 48 | + uses: docker/setup-buildx-action@v3 |
| 49 | + |
| 50 | + - name: Login to DockerHub |
| 51 | + uses: docker/login-action@v3 |
| 52 | + with: |
| 53 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 54 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: Build and Push Docker Image |
| 57 | + id: docker_build_release |
| 58 | + uses: docker/build-push-action@v5 |
| 59 | + with: |
| 60 | + context: ./apps/user/ |
| 61 | + file: ./apps/user/Dockerfile |
| 62 | + push: true |
| 63 | + tags: greenstand/treetracker-wallet-monorepo-user-api:${{ steps.package-version.outputs.current-version }} |
| 64 | + |
| 65 | + outputs: |
| 66 | + bumped_version: ${{ steps.package-version.outputs.current-version }} |
| 67 | + |
| 68 | + deploy: |
| 69 | + if: ${{ needs.release.result == 'success' }} && !contains(github.event.head_commit.message, 'skip-ci') |
| 70 | + name: Deploy to Dev Environment |
| 71 | + runs-on: ubuntu-latest |
| 72 | + needs: release |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - name: Install Kustomize |
| 77 | + run: | |
| 78 | + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash |
| 79 | +
|
| 80 | + - name: Update Kustomize Image |
| 81 | + run: | |
| 82 | + (cd apps/user/deployment/base && kustomize edit set image greenstand/treetracker-wallet-monorepo-user-api:${{ needs.release.outputs.bumped_version }}) |
| 83 | +
|
| 84 | + - name: Install DigitalOcean CLI |
| 85 | + uses: digitalocean/action-doctl@v2 |
| 86 | + with: |
| 87 | + token: ${{ secrets.DEV_DIGITALOCEAN_TOKEN }} |
| 88 | + |
| 89 | + - name: Save Kubernetes Config |
| 90 | + run: doctl kubernetes cluster kubeconfig save ${{ secrets.DEV_CLUSTER_NAME }} |
| 91 | + |
| 92 | + - name: Deploy to Kubernetes |
| 93 | + run: | |
| 94 | + kustomize build apps/user/deployment/overlays/development | \ |
| 95 | + kubectl apply -n ${{ secrets.K8S_NAMESPACE }} --wait -f - |
0 commit comments