Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preview takeover #53

Merged
merged 45 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
900f61e
fix: preview takeover
patrickleet Oct 26, 2022
05bf93b
fix: run syntax
patrickleet Oct 26, 2022
e6d373f
fix: run syntax
patrickleet Oct 27, 2022
72e2389
fix: cleanup
patrickleet Oct 27, 2022
e699b9a
fix: dockerignore + run in parallel + debug log
patrickleet Oct 27, 2022
0424d59
fix: more debug logs
patrickleet Oct 27, 2022
ab7264a
fix: repo name + ensure dir exists
patrickleet Oct 27, 2022
91dd09b
fix: typo
patrickleet Oct 27, 2022
7b6fb83
fix: helm path
patrickleet Oct 27, 2022
5669674
fix: push dir
patrickleet Oct 27, 2022
39cfb2d
fix: debug commit/push
patrickleet Oct 27, 2022
ca4e540
fix: extra "
patrickleet Oct 27, 2022
3b6fdf9
fix: missing $... derp getting late...
patrickleet Oct 27, 2022
28d71a7
fix: permission?
patrickleet Oct 27, 2022
731163f
fix: permissions
patrickleet Oct 27, 2022
254fe14
fix: permissions
patrickleet Oct 27, 2022
504ec0d
fix: typo
patrickleet Oct 27, 2022
89b64c2
fix: push tag to use as ref
patrickleet Oct 27, 2022
8dbf99d
fix: push tag
patrickleet Oct 27, 2022
5b529f9
fix: checkout
patrickleet Oct 27, 2022
03e7203
fix: only commit when needed
patrickleet Oct 27, 2022
94b027a
fix: use baseRef as ref
patrickleet Oct 27, 2022
92edc92
fix: use baseRef as ref
patrickleet Oct 27, 2022
c7bf558
fix: rm checkout
patrickleet Oct 27, 2022
6b2ab20
fix: head ref
patrickleet Oct 27, 2022
bb63ce5
fix: tag not needed using head ref
patrickleet Oct 27, 2022
8d2ae55
fix: project name
patrickleet Oct 27, 2022
f14ee90
fix: syncPolicy createNamespace
patrickleet Oct 27, 2022
25aa6b9
fix: commit message
patrickleet Oct 27, 2022
ea6f6dd
fix: create namespace syntax
patrickleet Oct 27, 2022
8a4ca77
fix: secret
patrickleet Oct 28, 2022
2babe40
fix: secret
patrickleet Oct 28, 2022
f41dd4a
feat: preview resources
patrickleet Oct 28, 2022
f85c618
fix: DEBUG env var
patrickleet Oct 28, 2022
8d8ef61
fix: fix mismatch and shorten resource names
patrickleet Oct 28, 2022
6fb6b59
fix: full internal dns
patrickleet Oct 28, 2022
feefae0
fix: dont fail if no changes
patrickleet Oct 28, 2022
937e2d7
fix: create more specific tag with each commit
patrickleet Oct 28, 2022
5a476a9
fix: tags
patrickleet Oct 28, 2022
823bf0a
fix: tags
patrickleet Oct 28, 2022
cb39d9e
fix: probe delay
patrickleet Oct 28, 2022
6f709dc
fix: test
patrickleet Oct 28, 2022
890928b
fix: ns match
patrickleet Oct 28, 2022
123e326
fix: project names should contain preview for searching for them in ui
patrickleet Oct 28, 2022
8cb0557
feat: delete preview on pr close
patrickleet Oct 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github/
helm/
preview/
4 changes: 2 additions & 2 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 16 additions & 21 deletions .github/workflows/pr-close.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
78 changes: 29 additions & 49 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


7 changes: 6 additions & 1 deletion .github/workflows/publish-and-promote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions helm/templates/external-secret-web3auth.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion helm/templates/ksvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
6 changes: 3 additions & 3 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions preview/helm/templates/preview-resources.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion preview/helm/values.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pr: pr-0
pr:
headRef:
tag: