-
Notifications
You must be signed in to change notification settings - Fork 1
133 lines (127 loc) · 4.8 KB
/
deploy-preview.yaml
File metadata and controls
133 lines (127 loc) · 4.8 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
# Workflow for making a preview deployment of the blog
name: Deploy blog preview
on:
pull_request:
types:
- opened
- synchronize
- reopened
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# 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@v4
- name: Docker image metadata
id: meta
uses: docker/metadata-action@v5
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@v4
with:
node-version: "20.17.0"
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Set up Docker
uses: docker/login-action@v3
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@v6
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]
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
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Helm
uses: azure/setup-helm@v4
- name: Deploy helm chart
env:
RELEASE: renku-blog-ci-${{ github.event.number }}
KUBECONFIG: "${{ github.workspace }}/renkubot-kube.config"
RENKUBOT_KUBECONFIG: ${{ secrets.RENKUBOT_DEV_KUBECONFIG }}
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 }}
echo "$RENKUBOT_KUBECONFIG" > "$KUBECONFIG" && chmod 400 "$KUBECONFIG"
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@v3
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@v4
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"