diff --git a/.github/workflows/node-api-ci.yaml b/.github/workflows/node-api-ci.yaml index f13ec05..1398894 100644 --- a/.github/workflows/node-api-ci.yaml +++ b/.github/workflows/node-api-ci.yaml @@ -7,10 +7,6 @@ on: paths: - services/node-api/** - .github/workflows/node-api-ci.yaml - pull_request: - paths: - - services/node-api/** - - .github/workflows/node-api-ci.yaml permissions: contents: read @@ -63,7 +59,6 @@ jobs: context: services/node-api push: true platforms: linux/amd64,linux/arm64 - tags: | ${{ env.IMAGE_NAME }}:main ${{ env.IMAGE_NAME }}:${{ github.sha }} diff --git a/.github/workflows/node-api-preview.yaml b/.github/workflows/node-api-preview.yaml index a67e088..95be0b8 100644 --- a/.github/workflows/node-api-preview.yaml +++ b/.github/workflows/node-api-preview.yaml @@ -11,8 +11,9 @@ on: - .github/workflows/node-api-preview.yaml permissions: - contents: read + contents: write packages: write + pull-requests: read env: IMAGE_NAME: ghcr.io/${{ github.repository }}/node-api @@ -67,3 +68,60 @@ jobs: push: true platforms: linux/amd64,linux/arm64 tags: ${{ steps.image.outputs.image }} + + - name: Checkout main for GitOps update + uses: actions/checkout@v4 + with: + ref: main + + - name: Generate preview application + run: | + PR_NUMBER="${{ github.event.pull_request.number }}" + PREVIEW_NAME="node-api-pr-${PR_NUMBER}" + PREVIEW_NAMESPACE="preview-node-api-pr-${PR_NUMBER}" + IMAGE_TAG="${{ steps.image.outputs.tag }}" + + mkdir -p previews/node-api + + { + echo "apiVersion: argoproj.io/v1alpha1" + echo "kind: Application" + echo "metadata:" + echo " name: ${PREVIEW_NAME}" + echo " namespace: argo-cd" + echo "spec:" + echo " project: default" + echo " source:" + echo " repoURL: https://github.com/devshinthant/internal-developer-platform.git" + echo " targetRevision: main" + echo " path: charts/node-api" + echo " helm:" + echo " values: |" + echo " image:" + echo " tag: ${IMAGE_TAG}" + echo " replicaCount: 1" + echo " destination:" + echo " server: https://kubernetes.default.svc" + echo " namespace: ${PREVIEW_NAMESPACE}" + echo " syncPolicy:" + echo " automated:" + echo " prune: true" + echo " selfHeal: true" + echo " syncOptions:" + echo " - CreateNamespace=true" + } > "previews/node-api/pr-${PR_NUMBER}.yaml" + + - name: Commit preview application + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + git add "previews/node-api/pr-${{ github.event.pull_request.number }}.yaml" + + if git diff --cached --quiet; then + echo "No preview changes to commit" + exit 0 + fi + + git commit -m "Update node-api preview for PR #${{ github.event.pull_request.number }}" + git push origin HEAD:main diff --git a/charts/node-api/templates/deployment.yaml b/charts/node-api/templates/deployment.yaml index 86270f5..3762944 100644 --- a/charts/node-api/templates/deployment.yaml +++ b/charts/node-api/templates/deployment.yaml @@ -33,6 +33,3 @@ spec: port: {{ .Values.service.targetPort }} resources: {{- toYaml .Values.resources | nindent 12 }} - imagePullSecrets: - {{- toYaml .Values.imagePullSecrets | nindent 8 }} -