Skip to content

Commit 7eba0b7

Browse files
committed
Set up automated deploy to kubernetes
1 parent 0027484 commit 7eba0b7

File tree

4 files changed

+95
-3
lines changed

4 files changed

+95
-3
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,13 @@ jobs:
9292
fi
9393
9494
publish-docker:
95-
name: Build & publish container to Docker Hub
95+
name: Build & publish container
9696
if: github.ref == 'refs/heads/main' || (github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/dependabot/'))
9797
runs-on: ubuntu-latest
9898
needs: build
99+
permissions:
100+
contents: read
101+
packages: write
99102
steps:
100103
- uses: actions/checkout@v4
101104

@@ -104,6 +107,13 @@ jobs:
104107
name: out
105108
path: out
106109

110+
- name: Log in to GHCR
111+
uses: docker/login-action@v3
112+
with:
113+
registry: ghcr.io
114+
username: ${{ github.repository_owner }}
115+
password: ${{ secrets.GITHUB_TOKEN }}
116+
107117
- uses: docker/setup-buildx-action@v3
108118
- name: Login to DockerHub
109119
uses: docker/login-action@v3
@@ -116,14 +126,16 @@ jobs:
116126
uses: docker/metadata-action@v5
117127
with:
118128
github-token: ${{ secrets.GITHUB_TOKEN }}
119-
images: httptoolkit/website
129+
images: |
130+
httptoolkit/website
131+
ghcr.io/httptoolkit/website
120132
tags: |
121133
type=raw,value=prod,enable=${{ github.ref == 'refs/heads/main' }}
122134
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
123135
type=raw,value=staging,enable=${{ github.ref == 'refs/heads/next' }}
124136
type=sha
125137
126-
- name: Publish to Docker Hub
138+
- name: Publish container
127139
uses: docker/build-push-action@v5
128140
with:
129141
context: .
@@ -137,6 +149,27 @@ jobs:
137149
runs-on: ubuntu-latest
138150
needs: publish-docker
139151
steps:
152+
- uses: actions/checkout@v4
153+
154+
- name: Configure Kubectl
155+
run: |
156+
kubectl config set-cluster scw-cluster \
157+
--server="${{ vars.K8S_SERVER_ADDRESS }}" \
158+
--certificate-authority=<(echo "${{ vars.K8S_CA_CERT }}" | base64 -d) \
159+
--embed-certs=true
160+
161+
kubectl config set-credentials deployer --token="${{ secrets.K8S_DEPLOY_TOKEN }}"
162+
163+
kubectl config set-context default --cluster=scw-cluster --user=deployer
164+
kubectl config use-context default
165+
166+
- name: Deploy to Kubernetes
167+
run: |
168+
sed "s|/website:latest|/website:${{ vars.DOCKER_IMAGE_TAG }}|g" deploy/deployment.yaml | \
169+
kubectl apply -f - \
170+
-f deploy/service.yaml \
171+
-f deploy/routes.yaml
172+
140173
- name: Redeploy container
141174
uses: httptoolkit/deploy-scaleway-serverless-container-action@v1
142175
with:

deploy/deployment.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: httptoolkit-website
5+
namespace: httptoolkit-website
6+
spec:
7+
replicas: 1
8+
selector:
9+
matchLabels:
10+
app: httptoolkit-website
11+
template:
12+
metadata:
13+
labels:
14+
app: httptoolkit-website
15+
spec:
16+
containers:
17+
- name: server
18+
image: ghcr.io/httptoolkit/website:latest # GHA replaces :latest on build
19+
ports:
20+
- containerPort: 4000
21+
env:
22+
- name: DOMAIN
23+
value: "http://:4000"

deploy/routes.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: httptoolkit-website-route
5+
namespace: httptoolkit-website
6+
spec:
7+
parentRefs:
8+
- name: primary-gateway
9+
namespace: gateway
10+
sectionName: https-httptoolkit-tech
11+
- name: secondary-gateway
12+
namespace: gateway
13+
sectionName: https-httptoolkit-tech
14+
hostnames:
15+
- "httptoolkit.com"
16+
rules:
17+
- matches:
18+
- path:
19+
type: PathPrefix
20+
value: /
21+
backendRefs:
22+
- name: httptoolkit-website
23+
port: 4000

deploy/service.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: httptoolkit-website
5+
namespace: httptoolkit-website
6+
spec:
7+
selector:
8+
app: httptoolkit-website
9+
ports:
10+
- name: http-port
11+
protocol: TCP
12+
port: 4000
13+
targetPort: 4000

0 commit comments

Comments
 (0)