Skip to content

Commit 1c18f7a

Browse files
committed
deploy on new infra
1 parent e389eab commit 1c18f7a

File tree

5 files changed

+109
-26
lines changed

5 files changed

+109
-26
lines changed

.github/workflows/deploy.yml

+42-16
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,50 @@ on:
55
branches: [ master ]
66
workflow_dispatch:
77

8+
env:
9+
NOMAD_VERSION: 1.7.7
10+
811
jobs:
912
deploy:
1013
runs-on: ubuntu-latest
1114

1215
steps:
13-
- name: Git checkout
14-
uses: actions/checkout@v3
15-
with:
16-
fetch-depth: 0
17-
18-
# See the following link for documentation:
19-
# https://github.com/marketplace/actions/dokku
20-
- name: Push to sips
21-
uses: dokku/[email protected]
22-
with:
23-
ssh_private_key: ${{ secrets.SIPS_GLOBAL_DEPLOY_KEY }}
24-
git_remote_url: ssh://[email protected]/zfinger
25-
# force might feel risky, but there is no good reason why the server
26-
# should ever not be a mirror of the deploy branch. And the errors we
27-
# could get otherwise would probably be nasty to deal with
28-
git_push_flags: --force
16+
- name: Git checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Set environment variables
20+
run: |
21+
cat >> "$GITHUB_ENV" <<EOF
22+
latest=ghcr.io/${{ github.repository }}:latest
23+
current=ghcr.io/${{ github.repository }}:$(git rev-parse --short ${{ github.sha }})
24+
EOF
25+
26+
- name: Download Nomad
27+
run: |
28+
curl -LO https://releases.hashicorp.com/nomad/${{ env.NOMAD_VERSION }}/nomad_${{ env.NOMAD_VERSION }}_linux_amd64.zip
29+
unzip -d /usr/local/bin nomad_${{ env.NOMAD_VERSION }}_linux_amd64.zip nomad
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to ghcr.io
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ghcr.io
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Build and push
42+
uses: docker/build-push-action@v5
43+
with:
44+
push: true
45+
tags: ${{ env.latest }},${{ env.current }}
46+
cache-from: type=gha
47+
cache-to: type=gha,mode=max
48+
49+
- name: Deploy to nomad
50+
env:
51+
NOMAD_ADDR: ${{ vars.NOMAD_ADDR }}
52+
NOMAD_TOKEN: ${{ secrets.NOMAD_TOKEN }}
53+
run: |
54+
nomad run -var=image_tag=${{ env.current }} job.nomad.hcl

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ Information displayed in `hodis` is `ugKthid`,`uid`,`on`,`mail`,`givenName`,`dis
2828
## Environment variables
2929
Required environment variables:
3030
```
31-
AWS_ACCESS_KEY_ID=<AWS_ACCESS_KEY_ID>
32-
AWS_SECRET_ACCESS_KEY=<AWS_SECRET_ACCESS_KEY>
33-
LOGIN_API_KEY=<LOGIN_API_KEY>
31+
AWS_ACCESS_KEY_ID=<AWS_ACCESS_KEY_ID>
32+
AWS_SECRET_ACCESS_KEY=<AWS_SECRET_ACCESS_KEY>
33+
LOGIN_API_KEY=<LOGIN_API_KEY>
3434
3535
## Optional
36-
S3_BUCKET=zfinger
37-
HODIS_HOST=https://hodis.datasektionen.se
38-
LOGIN_HOST=https://login.datasektionen.se
36+
S3_BUCKET=zfinger
37+
HODIS_HOST=https://hodis.datasektionen.se
38+
LOGIN_API_URL=https://login.datasektionen.se
39+
LOGIN_FRONTEND_URL=https://login.datasektionen.se
3940
```

app.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
app.wsgi_app = ProxyFix(app.wsgi_app)
2121

2222
LOGIN_API_KEY = getenv('LOGIN_API_KEY')
23-
LOGIN_HOST = getenv('LOGIN_HOST', 'https://login.datasektionen.se')
23+
LOGIN_API_URL = getenv('LOGIN_API_URL', 'https://login.datasektionen.se')
24+
LOGIN_FRONTEND_URL = getenv('LOGIN_FRONTEND_URL', 'https://login.datasektionen.se')
2425
HODIS_HOST = getenv('HODIS_HOST', 'https://hodis.datasektionen.se')
2526

2627
MISSING = s3.get('missing.svg')['Body'].read()
@@ -38,7 +39,7 @@ def verify_token(token: str):
3839
return login_cache[token][0]
3940

4041
payload = {'format': 'json', 'api_key': LOGIN_API_KEY}
41-
response = get(f'{LOGIN_HOST}/verify/{token}', params=payload)
42+
response = get(f'{LOGIN_API_URL}/verify/{token}', params=payload)
4243
if response.status_code == 200:
4344
user = response.json()['user']
4445
login_cache[token] = (user, datetime.now())
@@ -60,7 +61,7 @@ def wrapped_func(*args, **kwargs):
6061
user = None if token is None else verify_token(token)
6162

6263
if user is None:
63-
return redirect(f'{LOGIN_HOST}/login?callback={url_quote(request.base_url)}?token=')
64+
return redirect(f'{LOGIN_FRONTEND_URL}/login?callback={url_quote(request.base_url)}?token=')
6465

6566
kwargs[user_param_name] = user
6667
return func(*args, **kwargs)

docker-compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ services:
33
web:
44
build: .
55
env_file:
6-
- variables.env
6+
- .env
77
ports:
88
- "5000:5000"

job.nomad.hcl

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
job "zfinger" {
2+
type = "service"
3+
4+
group "zfinger" {
5+
network {
6+
port "http" {
7+
to = 5000
8+
}
9+
}
10+
11+
service {
12+
name = "zfinger"
13+
port = "http"
14+
provider = "nomad"
15+
tags = [
16+
"traefik.enable=true",
17+
"traefik.http.routers.zfinger.rule=Host(`zfinger.datasektionen.se`)",
18+
"traefik.http.routers.zfinger.tls.certresolver=default",
19+
]
20+
}
21+
22+
task "zfinger" {
23+
driver = "docker"
24+
25+
config {
26+
image = var.image_tag
27+
ports = ["http"]
28+
}
29+
30+
template {
31+
data = <<ENV
32+
{{ with nomadVar "nomad/jobs/zfinger" }}
33+
AWS_SECRET_ACCESS_KEY={{ .aws_secret_access_key }}
34+
LOGIN_API_KEY={{ .login_api_key }}
35+
{{ end }}
36+
AWS_ACCESS_KEY_ID=AKIATUCF4UAO3OIEOFJA
37+
LOGIN_FRONTEND_URL=https://logout.datasektionen.se/legacyapi
38+
LOGIN_API_URL=http://logout.nomad.dsekt.internal.se/legacyapi
39+
HODIS_HOST=https://hodis.datasektionen.se
40+
ENV
41+
destination = "local/.env"
42+
env = true
43+
}
44+
45+
resources {
46+
memory = 80
47+
}
48+
}
49+
}
50+
}
51+
52+
variable "image_tag" {
53+
type = string
54+
default = "ghcr.io/datasektionen/zfinger:latest"
55+
}

0 commit comments

Comments
 (0)