Skip to content

Commit 355a213

Browse files
committed
Setup a basic Docker-based deploy test
1 parent 30d611c commit 355a213

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git/
2+
node_modules/

.github/workflows/ci.yml

+62-3
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ jobs:
4444
path: dist/*
4545
if-no-files-found: error
4646

47-
publish:
48-
name: Deploy ${{ (github.ref == 'refs/heads/master' && 'to production') || 'preview' }}
47+
publish-netlify:
48+
name: Deploy ${{ (github.ref == 'refs/heads/master' && 'to Netlify production') || 'Netlify preview' }}
4949
if: github.event_name == 'push'
5050
runs-on: ubuntu-latest
5151
container: httptoolkit/act-build-base
@@ -73,4 +73,63 @@ jobs:
7373
env:
7474
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
7575
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
76-
timeout-minutes: 1
76+
timeout-minutes: 1
77+
78+
publish-hidora:
79+
name: Deploy to Docker Hub & Hidora
80+
if: github.event_name != 'pull_request'
81+
runs-on: ubuntu-latest
82+
container: httptoolkit/act-build-base
83+
needs: build
84+
steps:
85+
- uses: actions/checkout@v2
86+
87+
- uses: actions/download-artifact@v2
88+
with:
89+
name: dist
90+
path: dist
91+
92+
- uses: docker/setup-buildx-action@v1
93+
- name: Login to DockerHub
94+
if: github.event_name != 'pull_request'
95+
uses: docker/login-action@v2
96+
with:
97+
username: ${{ secrets.DOCKERHUB_USERNAME }}
98+
password: ${{ secrets.DOCKERHUB_TOKEN }}
99+
100+
- name: Extract Docker metadata
101+
id: meta
102+
uses: docker/metadata-action@v3
103+
with:
104+
github-token: ${{ secrets.GITHUB_TOKEN }}
105+
images: httptoolkit/ui
106+
tags: |
107+
type=raw,value=prod,enable={{is_default_branch}}
108+
type=raw,value=latest,enable={{is_default_branch}}
109+
type=sha
110+
111+
- name: Deploy to Docker Hub
112+
uses: docker/build-push-action@v2
113+
with:
114+
context: .
115+
push: ${{ github.event_name != 'pull_request' }}
116+
tags: ${{ steps.meta.outputs.tags }}
117+
labels: ${{ steps.meta.outputs.labels }}
118+
119+
- name: Redeploy site
120+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
121+
run: |
122+
sleep 30 # Wait for Docker Hub to fully publish
123+
124+
# Trigger a container redeploy:
125+
curl "https://app.hidora.com/1.0/environment/control/rest/redeploycontainersbygroup?session=$HIDORA_API_TOKEN&envName=htk-ui&nodeGroup=cp&tag=prod&useExistingVolumes=true" | \
126+
tee /dev/stderr | \
127+
grep -q 'Node has been successfully updated'
128+
129+
# Clear CDN cache to re-request content:
130+
curl -f --request POST \
131+
--url https://api.bunny.net/pullzone/1110200/purgeCache \
132+
--header "AccessKey: $BUNNY_SITE_API_KEY"
133+
env:
134+
HIDORA_API_TOKEN: ${{ secrets.HIDORA_API_TOKEN }}
135+
BUNNY_SITE_API_KEY: ${{ secrets.BUNNY_SITE_API_KEY }}

Caddyfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{$DOMAIN:http://localhost} {
2+
encode zstd gzip
3+
4+
header *.wasm Content-Type "application/wasm"
5+
6+
root * /site
7+
try_files {path} /index.html
8+
file_server
9+
10+
# Cache responses for 1 minute, validate async during next 10 minutes, or
11+
# continue serving old data as-is for up to 24 hours if this server stops
12+
# responding/returns errors.
13+
@get method GET
14+
header @get Cache-Control "public, max-age=60, stale-while-revalidate=600, stale-if-error=86400"
15+
16+
header Content-Security-Policy "frame-ancestors 'none'"
17+
header X-Clacks-Overhead "GNU Terry Pratchett" # https://xclacksoverhead.org
18+
}

Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM caddy:2.6.1-alpine
2+
3+
RUN mkdir /site
4+
5+
WORKDIR /site
6+
7+
COPY ./dist /site
8+
COPY ./Caddyfile /etc/caddy/Caddyfile

0 commit comments

Comments
 (0)