Skip to content

Commit 795f7f6

Browse files
committed
Publish container to GHCR & auto-deploy to k8s
1 parent 02bc0c2 commit 795f7f6

File tree

4 files changed

+98
-3
lines changed

4 files changed

+98
-3
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ jobs:
7575
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # To pull server without rate limit issues in CI
7676

7777
publish-docker:
78-
name: Build & publish container to Docker Hub
78+
name: Build & publish container
7979
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/dependabot/')
8080
runs-on: ubuntu-latest
8181
needs: [build, test-windows-build]
82+
permissions:
83+
contents: read
84+
packages: write
8285
steps:
8386
- uses: actions/checkout@v4
8487

@@ -87,6 +90,13 @@ jobs:
8790
name: dist
8891
path: dist
8992

93+
- name: Log in to GHCR
94+
uses: docker/login-action@v3
95+
with:
96+
registry: ghcr.io
97+
username: ${{ github.repository_owner }}
98+
password: ${{ secrets.GITHUB_TOKEN }}
99+
90100
- uses: docker/setup-buildx-action@v3
91101

92102
- name: Login to DockerHub
@@ -100,13 +110,15 @@ jobs:
100110
uses: docker/metadata-action@v5
101111
with:
102112
github-token: ${{ secrets.GITHUB_TOKEN }}
103-
images: httptoolkit/ui
113+
images: |
114+
httptoolkit/ui
115+
ghcr.io/httptoolkit/ui
104116
tags: |
105117
type=raw,value=prod,enable={{is_default_branch}}
106118
type=raw,value=latest,enable={{is_default_branch}}
107119
type=sha
108120
109-
- name: Build and publish to Docker Hub
121+
- name: Build and publish
110122
uses: docker/build-push-action@v5
111123
with:
112124
context: .
@@ -117,9 +129,33 @@ jobs:
117129
publish-scaleway:
118130
name: Deploy to Scaleway
119131
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
132+
environment: production
120133
runs-on: ubuntu-latest
121134
needs: publish-docker
122135
steps:
136+
- uses: actions/checkout@v4
137+
138+
- name: Configure Kubectl
139+
run: |
140+
kubectl config set-cluster scw-cluster \
141+
--server="${{ vars.K8S_SERVER_ADDRESS }}" \
142+
--certificate-authority=<(echo "${{ vars.K8S_CA_CERT }}" | base64 -d) \
143+
--embed-certs=true
144+
145+
kubectl config set-credentials deployer --token="${{ secrets.K8S_DEPLOY_TOKEN }}"
146+
147+
kubectl config set-context default --cluster=scw-cluster --user=deployer
148+
kubectl config use-context default
149+
150+
- name: Deploy to Kubernetes
151+
run: |
152+
sed "s|/ui:latest|/ui:${GITHUB_SHA::7}|g" deploy/deployment.yaml | \
153+
kubectl apply -f - \
154+
-f deploy/service.yaml \
155+
-f deploy/routes.yaml
156+
157+
kubectl rollout status deployment/httptoolkit-ui -n httptoolkit-ui
158+
123159
- name: Redeploy container
124160
uses: httptoolkit/scaleway-serverless-container-deploy-action@v1
125161
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-ui
5+
namespace: httptoolkit-ui
6+
spec:
7+
replicas: 1
8+
selector:
9+
matchLabels:
10+
app: httptoolkit-ui
11+
template:
12+
metadata:
13+
labels:
14+
app: httptoolkit-ui
15+
spec:
16+
containers:
17+
- name: server
18+
image: ghcr.io/httptoolkit/ui: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-ui-route
5+
namespace: httptoolkit-ui
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+
- "ui-backend.httptoolkit.tech"
16+
rules:
17+
- matches:
18+
- path:
19+
type: PathPrefix
20+
value: /
21+
backendRefs:
22+
- name: httptoolkit-ui
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-ui
5+
namespace: httptoolkit-ui
6+
spec:
7+
selector:
8+
app: httptoolkit-ui
9+
ports:
10+
- name: http-port
11+
protocol: TCP
12+
port: 4000
13+
targetPort: 4000

0 commit comments

Comments
 (0)