Skip to content

Commit ec6ab64

Browse files
committed
Set up automatic deployment to k8s
1 parent 6a5d4f7 commit ec6ab64

File tree

4 files changed

+89
-4
lines changed

4 files changed

+89
-4
lines changed

.github/workflows/build-and-deploy.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: CI
22
on: [push]
33
jobs:
4-
publish-hidora:
5-
name: Deploy to Docker Hub & Scaleway
6-
if: github.event_name != 'pull_request'
4+
deploy:
5+
name: Publish container and deploy
6+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
77
runs-on: ubuntu-latest
8+
environment: production
89
permissions:
910
contents: read
1011
packages: write
@@ -47,7 +48,26 @@ jobs:
4748
labels: ${{ steps.meta.outputs.labels }}
4849
build-args: VERSION=${{ github.sha }}
4950

50-
- name: Redeploy container
51+
- name: Configure Kubectl
52+
run: |
53+
kubectl config set-cluster scw-cluster \
54+
--server="${{ vars.K8S_SERVER_ADDRESS }}" \
55+
--certificate-authority=<(echo "${{ vars.K8S_CA_CERT }}" | base64 -d) \
56+
--embed-certs=true
57+
58+
kubectl config set-credentials deployer --token="${{ secrets.K8S_DEPLOY_TOKEN }}"
59+
60+
kubectl config set-context default --cluster=scw-cluster --user=deployer
61+
kubectl config use-context default
62+
63+
- name: Deploy to Kubernetes
64+
run: |
65+
sed "s|/anonymizing-reverse-proxy:latest|/anonymizing-reverse-proxy:sha-${GITHUB_SHA::7}|g" deploy/deployment.yaml | \
66+
kubectl apply -f - \
67+
-f deploy/service.yaml \
68+
-f deploy/routes.yaml
69+
70+
- name: Redeploy SCW container
5171
uses: httptoolkit/scaleway-serverless-container-deploy-action@v1
5272
with:
5373
container_id: ${{ vars.SCW_API_CONTAINER_ID }}

deploy/deployment.yaml

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

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: anonymizing-reverse-proxy-route
5+
namespace: anonymizing-reverse-proxy
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+
- "anonymizing-reverse-proxy.httptoolkit.tech"
16+
rules:
17+
- matches:
18+
- path:
19+
type: PathPrefix
20+
value: /
21+
backendRefs:
22+
- name: anonymizing-reverse-proxy
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: anonymizing-reverse-proxy
5+
namespace: anonymizing-reverse-proxy
6+
spec:
7+
selector:
8+
app: anonymizing-reverse-proxy
9+
ports:
10+
- name: http-port
11+
protocol: TCP
12+
port: 4000
13+
targetPort: 4000

0 commit comments

Comments
 (0)