diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8891c38 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.github/ +helm/ +preview/ \ No newline at end of file diff --git a/.env.production b/.env.production index 669e02f..f3c8f28 100644 --- a/.env.production +++ b/.env.production @@ -2,12 +2,12 @@ # For actual production define these env vars in the chart, and get secret values using ExternalSecrets # VITE_ for client side env vars VITE_WEB3AUTH_ISSUER=http://web3auth-service.example-prod-env.127.0.0.1.sslip.io -VITE_WEB3AUTH_ISSUER_INTERNAL=http://web3auth-service.example-prod-env +VITE_WEB3AUTH_ISSUER_INTERNAL=http://web3auth-service.example-prod-env.svc.cluster.local VITE_WEB3AUTH_CLIENT_ID=web3auth-client # build client secret with empty string in prod mode VITE_WEB3AUTH_CLIENT_SECRET= # VITE_WEB3AUTH_POST_LOGOUT_REDIRECT_URI=http://localhost:3000 // optional, just set to enable VITE_WEB3AUTH_TOKEN_REFRESH_MAX_RETRIES="5" VITE_GRAPHQL_URL=http://example-hasura.example-prod-env.127.0.0.1.sslip.io/v1/graphql -VITE_GRAPHQL_INTERNAL_URL=http://example-hasura.example-prod-env/v1/graphql +VITE_GRAPHQL_INTERNAL_URL=http://example-hasura.example-prod-env.svc.cluster.local/v1/graphql VITE_GRAPHQL_WS_URL=ws://example-hasura.example-prod-env.127.0.0.1.sslip.io/v1/graphql diff --git a/.github/workflows/pr-close.yaml b/.github/workflows/pr-close.yaml index 0e6a3fb..39aee31 100644 --- a/.github/workflows/pr-close.yaml +++ b/.github/workflows/pr-close.yaml @@ -10,28 +10,23 @@ jobs: steps: - - name: downcase REPO - run: | - echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} - - - name: Checkout + - name: Checkout Preview Environments Project uses: actions/checkout@v3 + with: + repository: cloudnativeentrepreneur/example-preview-envs + persist-credentials: false - - name: test + - name: Commit Preview Env Changes run: | - echo "Test" - - # - name: Setup Kube config - # uses: azure/k8s-set-context@v3 - # with: - # method: kubeconfig - # kubeconfig: ${{ secrets.KUBE_CONFIG }} - - # - name: Delete preview - # run: | - # # Install vCluster - # curl -s -L "https://github.com/loft-sh/vcluster/releases/latest" | sed -nE 's!.*"([^"]*vcluster-linux-amd64)".*!https://github.com\1!p' | xargs -n 1 curl -L -o vcluster && chmod +x vcluster; - # sudo mv vcluster /usr/local/bin; + rm helm/templates/${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}.yaml + 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 "remove: ${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}" - # # Delete the cluster - # vcluster delete demo-hasura-pr-${{ github.event.pull_request.number }} --namespace prs + - name: Push Preview Env Changes + uses: ad-m/github-push-action@master + with: + directory: previews + github_token: ${{ secrets.GH_ORG_TOKEN }} + repository: cloudnativeentrepreneur/example-preview-envs \ No newline at end of file diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index f670de4..96694f9 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -17,21 +17,30 @@ jobs: # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - - uses: actions/checkout@v2 + + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} cache: 'npm' - - run: npm ci - - run: npm run lint --if-present - - run: npm run build --if-present - - run: npm run test --if-present - - run: npx codecov + - name: Run Npm Quality Scripts + run: | + npm ci + npm run lint --if-present + npm run build --if-present + npm run test --if-present + npx codecov preview: - needs: quality + # needs: quality runs-on: ubuntu-latest + + permissions: + packages: write + contents: write + steps: - name: downcase REPO @@ -67,69 +76,40 @@ jobs: push: true tags: | ${{ steps.meta.outputs.tags }} + ghcr.io/${{ env.REPO }}:pr-${{ github.event.pull_request.number }}-${{ github.sha }} 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 + repository: cloudnativeentrepreneur/example-preview-envs 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: Create Preview from Helm template + run: | + mkdir -p previews/helm/templates + helm template preview/helm/ --set pr=pr-${{ github.event.pull_request.number }} --set tag=pr-${{ github.event.pull_request.number }}-${{ github.sha }} --set headRef=${{ github.head_ref }} > previews/helm/templates/${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}.yaml - - name: Commit Prod Env Changes + - name: Commit Preview Env Changes run: | cd previews + cat helm/templates/${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}.yaml 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 }}" + git commit -m "promote: ${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }} ${{ github.sha }}" - - name: Push prod + - name: Push Preview Env Changes uses: ad-m/github-push-action@master with: - path: previews + directory: previews github_token: ${{ secrets.GH_ORG_TOKEN }} - repository: cloudnativeentrepreneur/example-prod-env - # - name: Setup Kube config - # uses: azure/k8s-set-context@v3 - # with: - # method: kubeconfig - # kubeconfig: ${{ secrets.KUBE_CONFIG }} - - # - name: Deploy preview - # run: | - # # Install vCluster - # curl -s -L "https://github.com/loft-sh/vcluster/releases/latest" | sed -nE 's!.*"([^"]*vcluster-linux-amd64)".*!https://github.com\1!p' | xargs -n 1 curl -L -o vcluster && chmod +x vcluster; - # sudo mv vcluster /usr/local/bin; - - # # Create a cluster - # vcluster create example-hasura-pr-${{ github.event.pull_request.number }} --namespace prs --expose - # vcluster connect example-hasura-pr-${{ github.event.pull_request.number }} --namespace prs - # export KUBECONFIG=$PWD/kubeconfig.yaml - # sleep 5 - # kubectl get ingresses - - # # Deploy - # cd kustomize/overlays/preview - # kustomize edit set image ${{ env.REPO }}=${{ env.REPO }}:pr-${{ github.event.pull_request.number }} - # kustomize build | kubectl apply --filename - - # kubectl rollout status deployment example-hasura - # - name: Test - # run: | - # echo "I was to lazy to write tests" + repository: cloudnativeentrepreneur/example-preview-envs + diff --git a/.github/workflows/publish-and-promote.yaml b/.github/workflows/publish-and-promote.yaml index a5ee72b..105aafe 100644 --- a/.github/workflows/publish-and-promote.yaml +++ b/.github/workflows/publish-and-promote.yaml @@ -81,7 +81,12 @@ jobs: 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 }}" + if [[ `git status --porcelain` ]]; then + # Changes + git commit -m "feat: Promoting ${{ github.event.repository.name }} to ${{ github.ref_name }}" + else + # No changes + fi - name: Push prod uses: ad-m/github-push-action@master diff --git a/helm/templates/external-secret-web3auth.yaml b/helm/templates/external-secret-web3auth.yaml new file mode 100644 index 0000000..4aace2e --- /dev/null +++ b/helm/templates/external-secret-web3auth.yaml @@ -0,0 +1,13 @@ +apiVersion: external-secrets.io/v1beta1 +kind: ExternalSecret +metadata: + name: {{ .Values.service.name }}-web3auth +spec: + secretStoreRef: + name: fake + kind: ClusterSecretStore + target: + name: {{ .Values.service.name }}-web3auth + dataFrom: + - extract: + key: /web3auth diff --git a/helm/templates/ksvc.yaml b/helm/templates/ksvc.yaml index 2dedb62..cd478b4 100755 --- a/helm/templates/ksvc.yaml +++ b/helm/templates/ksvc.yaml @@ -41,7 +41,7 @@ spec: - name: WEB3AUTH_CLIENT_SECRET valueFrom: secretKeyRef: - name: web3auth + name: {{ .Values.service.name }}-web3auth key: clientSecret {{- range $pkey, $pval := .Values.env }} - name: {{ $pkey }} diff --git a/helm/values.yaml b/helm/values.yaml index 697b810..2da24fe 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -20,13 +20,13 @@ knative: probePath: / livenessProbe: - initialDelaySeconds: 90 + initialDelaySeconds: 0 periodSeconds: 10 successThreshold: 1 timeoutSeconds: 1 readinessProbe: - initialDelaySeconds: 90 - failureThreshold: 1 + initialDelaySeconds: 0 + failureThreshold: 3 periodSeconds: 10 successThreshold: 1 timeoutSeconds: 1 diff --git a/preview/helm/templates/preview-resources.yaml b/preview/helm/templates/preview-resources.yaml new file mode 100644 index 0000000..0cc979d --- /dev/null +++ b/preview/helm/templates/preview-resources.yaml @@ -0,0 +1,23 @@ + +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: example-ui-{{ .Values.pr }}-preview-resources + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + project: example-preview-envs + source: + path: resources/preview + repoURL: https://github.com/cloudnativeentrepreneur/example-preview-envs.git + targetRevision: HEAD + helm: + version: v3 + destination: + namespace: example-ui-{{ .Values.pr }}-preview + server: https://kubernetes.default.svc + syncPolicy: + automated: + selfHeal: true + prune: true \ No newline at end of file diff --git a/preview/helm/templates/application.yaml b/preview/helm/templates/preview.yaml similarity index 59% rename from preview/helm/templates/application.yaml rename to preview/helm/templates/preview.yaml index a8e1c95..848ccd0 100644 --- a/preview/helm/templates/application.yaml +++ b/preview/helm/templates/preview.yaml @@ -1,25 +1,29 @@ apiVersion: argoproj.io/v1alpha1 kind: Application metadata: - name: example-ui-preview-{{ .Values.pr }} + name: example-ui-{{ .Values.pr }}-preview namespace: argocd finalizers: - resources-finalizer.argocd.argoproj.io spec: - project: example-previews + project: example-preview-envs source: path: helm repoURL: https://github.com/cloudnativeentrepreneur/sveltekit-web3auth-template.git - targetRevision: {{ .Values.pr }} + targetRevision: {{ .Values.headRef }} helm: version: v3 values: | image: - tag: {{ .Values.pr }} + tag: {{ .Values.tag }} + env: + DEBUG: sveltekit-web3auth:* destination: - namespace: example-ui-preview-{{ .Values.pr }} + namespace: example-ui-{{ .Values.pr }}-preview server: https://kubernetes.default.svc syncPolicy: automated: selfHeal: true prune: true + syncOptions: + - CreateNamespace=true diff --git a/preview/helm/values.yaml b/preview/helm/values.yaml index e9413c3..c5e1aa6 100644 --- a/preview/helm/values.yaml +++ b/preview/helm/values.yaml @@ -1 +1,3 @@ -pr: pr-0 \ No newline at end of file +pr: +headRef: +tag: \ No newline at end of file