Repository navigation
107 lines (95 loc) · 3.98 KB
/
Copy pathmetrics.yml
File metadata and controls
107 lines (95 loc) · 3.98 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
name: Metrics site
# Builds metrics.getvalence.app, the public statistics site, whenever it or what it is built from
# changes on main, and puts it on its server: the image goes to GHCR, then the server is told over
# SSH to pull it and restart. The server keeps its own .env; nothing secret is copied to it.
on:
push:
branches: [main]
paths:
- 'apps/metrics/**'
- 'packages/ui/**'
- 'packages/contracts/**'
- 'pnpm-lock.yaml'
- '.github/workflows/metrics.yml'
workflow_dispatch:
concurrency:
group: metrics-${{ github.ref }}
cancel-in-progress: false
jobs:
image:
name: Build and push the image
if: github.repository == 'ValenceOSS/Valence'
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
file: apps/metrics/Dockerfile
platforms: linux/amd64
push: true
tags: |
ghcr.io/valenceoss/valence-metrics:latest
ghcr.io/valenceoss/valence-metrics:${{ github.sha }}
labels: |
org.opencontainers.image.title=Valence statistics
org.opencontainers.image.description=The public statistics site at metrics.getvalence.app
org.opencontainers.image.licenses=MIT
org.opencontainers.image.source=https://github.com/${{ github.repository }}
# Kept in the registry beside the image rather than in the Actions cache, which every
# workflow shares and which this image's layers crowded the CI's dependencies out of.
cache-from: type=registry,ref=ghcr.io/valenceoss/valence-metrics:buildcache
cache-to: type=registry,ref=ghcr.io/valenceoss/valence-metrics:buildcache,mode=max,image-manifest=true,oci-mediatypes=true
provenance: false
deploy:
name: Deploy to the server
if: github.repository == 'ValenceOSS/Valence'
needs: image
runs-on: ubuntu-24.04
permissions:
contents: read
packages: read
env:
SSH_HOST: ${{ secrets.METRICS_SSH_HOST }}
SSH_USER: ${{ secrets.METRICS_SSH_USER }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Trust the server and hold the key
env:
SSH_KEY: ${{ secrets.METRICS_SSH_KEY }}
SSH_KNOWN_HOSTS: ${{ secrets.METRICS_SSH_KNOWN_HOSTS }}
run: |
install -m 700 -d ~/.ssh
printf '%s\n' "$SSH_KEY" > ~/.ssh/metrics
chmod 600 ~/.ssh/metrics
printf '%s\n' "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Copy the compose file and the Caddyfile
run: >-
scp -i ~/.ssh/metrics -o StrictHostKeyChecking=yes
apps/metrics/deploy/compose.yaml apps/metrics/deploy/Caddyfile
"$SSH_USER@$SSH_HOST:/opt/valence-metrics/"
- name: Pull the new image and restart
env:
REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACTOR: ${{ github.actor }}
TAG: ${{ github.sha }}
run: |
printf '%s\n' "$REGISTRY_TOKEN" | ssh -i ~/.ssh/metrics -o StrictHostKeyChecking=yes \
"$SSH_USER@$SSH_HOST" \
"docker login ghcr.io -u '$ACTOR' --password-stdin && cd /opt/valence-metrics && export METRICS_TAG='$TAG' && docker compose pull && docker compose up -d --remove-orphans && docker image prune -f"
- name: Forget the key
if: always()
run: rm -f ~/.ssh/metrics