-
Notifications
You must be signed in to change notification settings - Fork 1
147 lines (140 loc) · 5.19 KB
/
deploy-preview.yaml
File metadata and controls
147 lines (140 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Workflow for making a preview deployment of the blog
name: Deploy blog preview
permissions:
contents: read
on:
pull_request:
types:
- opened
- synchronize
- reopened
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref || github.run_id }}
# Default to bash
defaults:
run:
shell: bash
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# Build job
build:
if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
outputs:
image: ${{ steps.docker_image.outputs.image }}
image_repository: ${{ steps.docker_image.outputs.image_repository }}
image_tag: ${{ steps.docker_image.outputs.image_tag }}
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Docker image metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: type=sha
- name: Extract Docker image name
id: docker_image
env:
IMAGE_TAGS: ${{ steps.meta.outputs.tags }}
run: |
IMAGE=$(echo "$IMAGE_TAGS" | cut -d" " -f1)
IMAGE_REPOSITORY=$(echo "$IMAGE" | cut -d":" -f1)
IMAGE_TAG=$(echo "$IMAGE" | cut -d":" -f2)
echo "image=$IMAGE" >> "$GITHUB_OUTPUT"
echo "image_repository=$IMAGE_REPOSITORY" >> "$GITHUB_OUTPUT"
echo "image_tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT"
- name: Set up node
uses: actions/setup-node@v6
with:
node-version: "22.18.0"
cache: npm
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v4
- name: Set up Docker
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: npm clean-install
- name: Build site
run: npm run build
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ steps.docker_image.outputs.image_repository }}:buildcache
cache-to: type=registry,ref=${{ steps.docker_image.outputs.image_repository }}:buildcache,mode=max
deploy:
# Deploy job
if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
needs: [build]
# NOTE: using GitHub deploy environments does not work with Azure at the moment
# environment:
# name: renku-blog-ci-${{ github.event.number }}
# url: https://renku-blog-ci-${{ github.event.number }}.dev.renku.ch
permissions:
contents: read
pull-requests: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Helm
uses: azure/setup-helm@v5
- name: Azure login
uses: azure/login@v3
with:
client-id: ${{ secrets.CI_RENKU_AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.CI_RENKU_AZURE_TENANT_ID }}
subscription-id: ${{ secrets.CI_RENKU_AZURE_SUBSCRIPTION_ID }}
- name: Set AKS context
uses: azure/aks-set-context@v5
with:
resource-group: "renku-dev"
cluster-name: "aks-switzerlandnorth-renku-dev"
- name: Deploy helm chart
env:
RELEASE: renku-blog-ci-${{ github.event.number }}
run: |
NAMESPACE=${RELEASE}
HOST=renku-blog-ci-${{ github.event.number }}.dev.renku.ch
IMAGE=$(echo "$IMAGE_TAGS" | cut -d" " -f1)
IMAGE_REPOSITORY=${{ needs.build.outputs.image_repository }}
IMAGE_TAG=${{ needs.build.outputs.image_tag }}
kubectl create namespace ${NAMESPACE} || true
helm upgrade --install ${RELEASE} ./helm-chart/renku-blog \
--namespace=${NAMESPACE} --timeout 5m --wait --wait-for-jobs \
--set image.repository=${IMAGE_REPOSITORY} --set image.tag=${IMAGE_TAG} \
--set ingress.enabled=true --set ingress.hosts[0].host=${HOST} \
--set ingress.hosts[0].paths[0].path="/" --set ingress.hosts[0].paths[0].pathType="Prefix" \
--set ingress.tls[0].secretName="${RELEASE}-tls" \
--set ingress.tls[0].hosts[0]=${HOST}
- name: Find deployment comment
uses: peter-evans/find-comment@v4
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number }}
# comment-author: "RenkuBot"
comment-author: "github-actions[bot]"
body-includes: You can access the deployment of this PR at
- name: Deployment comment
if: steps.find_comment.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v5
with:
# token: ${{ secrets.RENKUBOT_GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
You can access the deployment of this PR at https://renku-blog-ci-${{ github.event.number }}.dev.renku.ch
reactions: "rocket"