From 7a873e23f1c6d9070aec370264d8817881a7eb55 Mon Sep 17 00:00:00 2001 From: Patrick Lee Scott Date: Wed, 26 Oct 2022 18:39:44 -0500 Subject: [PATCH 1/2] feat: previews --- .github/workflows/pr.yaml | 35 +++++++++++++++++++++++++ preview/helm/Chart.yaml | 6 +++++ preview/helm/templates/application.yaml | 25 ++++++++++++++++++ preview/helm/values.yaml | 1 + 4 files changed, 67 insertions(+) create mode 100644 preview/helm/Chart.yaml create mode 100644 preview/helm/templates/application.yaml create mode 100644 preview/helm/values.yaml diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index a139d21..f9a0555 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -68,7 +68,41 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache,mode=max + + - name: Setup Helm + uses: azure/setup-helm@v3 + + - name: Checkout App + uses: actions/checkout@v3 + with: + path: app + - name: Checkout Preview Environments Project + uses: actions/checkout@v3 + with: + path: previews + repository: cloudnativeentrepreneur/example-previews + persist-credentials: false + fetch-depth: 0 + + - name: create preview from helm template + run: + - helm template app/preview/helm/ --set pr=pr-${{ github.event.pull_request.number }} > previews/helm/templates/pr-${{ github.event.pull_request.number }}.yaml + + - name: Commit Prod Env Changes + run: | + cd previews + 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 "feat: Promoting ${{ github.event.repository.name }} to ${{ github.ref_name }}" + + - name: Push prod + uses: ad-m/github-push-action@master + with: + path: previews + github_token: ${{ secrets.GH_ORG_TOKEN }} + repository: cloudnativeentrepreneur/example-prod-env # - name: Setup Kube config # uses: azure/k8s-set-context@v3 # with: @@ -96,3 +130,4 @@ jobs: # - name: Test # run: | # echo "I was to lazy to write tests" + diff --git a/preview/helm/Chart.yaml b/preview/helm/Chart.yaml new file mode 100644 index 0000000..e2ce9c1 --- /dev/null +++ b/preview/helm/Chart.yaml @@ -0,0 +1,6 @@ +# Helm chart.yaml +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: mychart +version: 1.0.0 diff --git a/preview/helm/templates/application.yaml b/preview/helm/templates/application.yaml new file mode 100644 index 0000000..a8e1c95 --- /dev/null +++ b/preview/helm/templates/application.yaml @@ -0,0 +1,25 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: example-ui-preview-{{ .Values.pr }} + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + project: example-previews + source: + path: helm + repoURL: https://github.com/cloudnativeentrepreneur/sveltekit-web3auth-template.git + targetRevision: {{ .Values.pr }} + helm: + version: v3 + values: | + image: + tag: {{ .Values.pr }} + destination: + namespace: example-ui-preview-{{ .Values.pr }} + server: https://kubernetes.default.svc + syncPolicy: + automated: + selfHeal: true + prune: true diff --git a/preview/helm/values.yaml b/preview/helm/values.yaml new file mode 100644 index 0000000..e9413c3 --- /dev/null +++ b/preview/helm/values.yaml @@ -0,0 +1 @@ +pr: pr-0 \ No newline at end of file From 27e40730fbf4aebf226aaada106dc9e7f1411c95 Mon Sep 17 00:00:00 2001 From: Patrick Lee Scott Date: Wed, 26 Oct 2022 18:45:17 -0500 Subject: [PATCH 2/2] fix: trigger --- .github/workflows/pr.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index f9a0555..f670de4 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -3,6 +3,8 @@ name: pr on: pull_request: + branches: + - main jobs: