Skip to content

Commit

Permalink
ci: add deploy on pr
Browse files Browse the repository at this point in the history
  • Loading branch information
choffmann committed Jun 10, 2024
1 parent 1e28577 commit 501db19
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
node-version-file: .node-version

- name: Install Yarn
run: npm install -g yarn
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/cleanup_pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'Cleanup Pull Request'
on:
pull_request:
types: [closed]

jobs:
cleanup-pr:
name: "Cleanup Pull Request"
runs-on: ubuntu-latest
continue-on-error: true
permissions:
contents: read
packages: write
actions: write
pull-requests: write

steps:
- name: Kubernetes login
uses: azure/k8s-set-context@v4
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}

- name: Delete Helm Chart
run: |
helm delete project-website-pr-${{ github.event.number }} --namespace project-website-pr-${{ github.event.number }}
- name: Delete Namespace
if: always()
run: |
kubectl delete namespace project-website-pr-${{ github.event.number }}
89 changes: 89 additions & 0 deletions .github/workflows/deploy_pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: "Deploy Pull Request"
on:
pull_request:
types: [labeled]

jobs:
deploy_pr:
name: "Deploy Pull Request"
runs-on: ubuntu-latest
if: ${{ github.event.label.name == 'deploy' }}
permissions:
contents: read
packages: write
actions: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: set lower case owner name
run: |
echo "REPO_LC=${REPO,,}" >>${GITHUB_ENV}
env:
REPO: "${{ github.repository }}"

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./.docker/Dockerfile.dev
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ env.REPO_LC }}-dev:pr-${{ github.event.number }}

- name: "Setup yq"
uses: dcarbone/[email protected]
with:
version: "v4.42.1"
force: true

- name: Change values in on-pr.yaml
run: |
yq -i '
.ingress.hosts[0].name = "pr-${{ github.event.number }}.website.dev.green-ecolution.de" |
.deployment.image.tag = "pr-${{ github.event.number }}" |
.deployment.name = "project-website-pr-${{ github.event.number }}" |
.deployment.namespace = "project-website-pr-${{ github.event.number }}"
' ./k8s/values/develop.yaml
- name: Kubernetes login
uses: azure/k8s-set-context@v4
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}

- name: Install Helm Chart
run: |
helm upgrade project-website-pr-${{ github.event.number }} ./k8s \
--install \
--namespace project-website-pr-${{ github.event.number }} \
--create-namespace \
--wait \
--values ./k8s/values.yaml \
--values ./k8s/values/develop.yaml \
- name: Post comment to Pull Request
uses: thollander/actions-comment-pull-request@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: |
Deployment of PR #${{ github.event.number }} successful :rocket:
You can access the deployment at [pr-${{ github.event.number }}.website.dev.green-ecolution.de](https://pr-${{ github.event.number }}.website.dev.green-ecolution.de) to review the changes :eyes:
:warning: **Please note that this deployment is temporary and will be deleted after the PR is closed.**

0 comments on commit 501db19

Please sign in to comment.