Skip to content

Commit

Permalink
feat: previews (#62)
Browse files Browse the repository at this point in the history
* feat: previews

* fix: chart version + shorten env
  • Loading branch information
patrickleet authored Oct 31, 2022
1 parent 8a2519e commit 8bf3c26
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 244 deletions.
48 changes: 29 additions & 19 deletions .github/workflows/pr-close.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,41 @@ jobs:

pr-close:
runs-on: ubuntu-latest

permissions:
issues: write
pull-requests: write
contents: write

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"
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 }}"
# - name: Setup Kube config
# uses: azure/k8s-set-context@v3
# with:
# method: kubeconfig
# kubeconfig: ${{ secrets.KUBE_CONFIG }}
- name: Push Preview Env Changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_ORG_TOKEN }}
repository: cloudnativeentrepreneur/example-preview-envs

# - 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;
- name: Create comment about garbage collection
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Your preview environment has been removed. It will be garbage collected soon.
# # Delete the cluster
# vcluster delete demo-hasura-pr-${{ github.event.pull_request.number }} --namespace prs
To create a new preview environment, open a new pull request.
edit-mode: replace
123 changes: 89 additions & 34 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: pr
on:

pull_request:
branches:
- main

jobs:

Expand All @@ -15,21 +17,32 @@ 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 test
- 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
issues: write
pull-requests: write

steps:

- name: downcase REPO
Expand Down Expand Up @@ -65,34 +78,76 @@ 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: 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"
- name: Checkout Preview Environments Project
uses: actions/checkout@v3
with:
path: previews
repository: cloudnativeentrepreneur/example-preview-envs
persist-credentials: false

- 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 }} \
--set repository.name=${{ github.event.repository.name }} \
> previews/helm/templates/${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}.yaml
- name: Commit Preview Env Changes
run: |
cd previews
if output=$(git status --porcelain) && [ -z "$output" ]; then
# Working directory clean
echo "No changes to commit"
else
# Uncommitted changes
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
git commit -m "promote: ${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }} ${{ github.sha }}"
fi
- 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

- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Your preview environment

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Your preview environment has been published! :rocket:
This service doesn't have a public URL.
You can verify the PR is ready with `kubectl`:
```bash
kubectl get all -n ${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }}-preview
```
edit-mode: replace
18 changes: 13 additions & 5 deletions .github/workflows/publish-and-promote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
context: .
push: true
tags: |
ghcr.io/${{ steps.meta.outputs.tags }}
${{ steps.meta.outputs.tags }}
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
Expand All @@ -78,10 +78,18 @@ jobs:

- name: Commit Prod Env Changes
run: |
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 output=$(git status --porcelain) && [ -z "$output" ]; then
# Working directory clean
echo "No changes to commit"
else
# Uncommitted changes
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
git commit -m "feat: Promoting ${{ github.event.repository.name }} to ${{ github.ref_name }}"
fi
- name: Push prod
uses: ad-m/github-push-action@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- run: npm ci
- run: npm run lint --if-present
- run: npm run build --if-present
- run: npm test
- run: npm run test --if-present
- run: npx codecov

release:
Expand Down
2 changes: 1 addition & 1 deletion helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
description: A Helm chart for Kubernetes
icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/d273e09/images/nodejs.png
name: example-hasura-projections-service
version: dev
version: 0.0.0-dev
11 changes: 0 additions & 11 deletions helm/Kptfile

This file was deleted.

1 change: 0 additions & 1 deletion helm/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions helm/templates/NOTES.txt

This file was deleted.

16 changes: 0 additions & 16 deletions helm/templates/_helpers.tpl

This file was deleted.

52 changes: 0 additions & 52 deletions helm/templates/deployment.yaml

This file was deleted.

29 changes: 0 additions & 29 deletions helm/templates/service.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions helm/templates/todo.completed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: todo.completed
annotations:
argocd.argoproj.io/sync-wave: "-1"
spec:
broker: todo-events
filter:
Expand Down
2 changes: 2 additions & 0 deletions helm/templates/todo.initialized.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: todo.initialized
annotations:
argocd.argoproj.io/sync-wave: "-1"
spec:
broker: todo-events
filter:
Expand Down
Loading

0 comments on commit 8bf3c26

Please sign in to comment.