Skip to content

Commit 69330ac

Browse files
authored
Merge pull request #100 from lsst-sqre/u/jsickcodes/deploy-2-0
Prepare Kubernetes deployment for v2
2 parents 1d4a0e8 + ba340f6 commit 69330ac

15 files changed

+151
-346
lines changed

.github/workflows/ci.yaml

+36-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
name: CI
22

3-
"on": [push]
3+
'on':
4+
push:
5+
branches-ignore:
6+
# These should always correspond to pull requests, so ignore them for
7+
# the push trigger and let them be triggered by the pull_request
8+
# trigger, avoiding running the workflow twice. This is a minor
9+
# optimization so there's no need to ensure this is comprehensive.
10+
- 'dependabot/**'
11+
- 'renovate/**'
12+
- 'tickets/**'
13+
- 'u/**'
14+
tags:
15+
- '*'
16+
pull_request: {}
417

518
jobs:
619
lint:
@@ -60,18 +73,20 @@ jobs:
6073
LTD_KEEPER_TEST_AWS_ID: ${{ secrets.LTD_KEEPER_TEST_AWS_ID }}
6174
LTD_KEEPER_TEST_AWS_SECRET: ${{ secrets.LTD_KEEPER_TEST_AWS_SECRET }}
6275
LTD_KEEPER_TEST_BUCKET: ${{ secrets.LTD_KEEPER_TEST_BUCKET }}
63-
run: tox -e typing,${{matrix.db}},coverage-report # run tox using Python in path
76+
run: tox -e typing,${{matrix.db}},coverage-report # run tox using Python in path
6477

6578
- name: Run tox without external services
6679
if: ${{ !(matrix.python != 3.9 && matrix.db != 'postgres') }}
67-
run: tox -e typing,${{matrix.db}},coverage-report # run tox using Python in path
80+
run: tox -e typing,${{matrix.db}},coverage-report # run tox using Python in path
6881

6982
docs:
7083
runs-on: ubuntu-latest
7184
needs: [lint]
7285

7386
steps:
7487
- uses: actions/checkout@v2
88+
with:
89+
fetch-depth: 0
7590

7691
- name: Set up Python
7792
uses: actions/setup-python@v2
@@ -106,15 +121,18 @@ jobs:
106121
needs: [test]
107122

108123
# Only do Docker builds of ticket branches and tagged releases, as well
109-
# as JSick Codes branches.
110-
if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/tickets/') || startsWith(github.ref, 'refs/heads/u/jsickcodes/')
124+
# as J.Sick Codes branches.
125+
# if: >
126+
# (startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/tickets/')) || startsWith(github.ref, 'refs/heads/u/jsickcodes/')
111127

112128
steps:
113129
- uses: actions/checkout@v2
130+
with:
131+
fetch-depth: 0
114132

115133
- name: Define the Docker tag
116134
id: vars
117-
run: echo ::set-output name=tag::$(bin/docker-tag.sh "$GITHUB_REF")
135+
run: echo ::set-output name=tag::$(bin/docker-tag.sh)
118136

119137
- name: Print the tag
120138
id: print
@@ -123,33 +141,26 @@ jobs:
123141
- name: Set up Docker Buildx
124142
uses: docker/setup-buildx-action@v1
125143

126-
- name: Cache Docker layers
127-
uses: actions/cache@v2
128-
with:
129-
path: /tmp/.buildx-cache
130-
key: ${{ runner.os }}-buildx-${{ github.sha }}
131-
restore-keys:
132-
${{ runner.os }}-buildx-
133-
134144
- name: Log in to Docker Hub
135145
uses: docker/login-action@v1
136146
with:
137147
username: ${{ secrets.DOCKER_USERNAME }}
138148
password: ${{ secrets.DOCKER_TOKEN }}
139149

150+
- name: Log in to GitHub Container Registry
151+
uses: docker/login-action@v1
152+
with:
153+
registry: ghcr.io
154+
username: ${{ github.repository_owner }}
155+
password: ${{ secrets.GITHUB_TOKEN }}
156+
140157
- name: Build and push
141158
uses: docker/build-push-action@v2
142159
with:
143160
context: .
144161
push: true
145-
tags: lsstsqre/ltdkeeper:${{ steps.vars.outputs.tag }}
146-
cache-from: type=local,src=/tmp/.buildx-cache
147-
cache-to: type=local,dest=/tmp/.buildx-cache-new
148-
149-
# Temp fix
150-
# https://github.com/docker/build-push-action/issues/252
151-
# https://github.com/moby/buildkit/issues/1896
152-
- name: Move cache
153-
run: |
154-
rm -rf /tmp/.buildx-cache
155-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
162+
tags: |
163+
lsstsqre/ltdkeeper:${{ steps.vars.outputs.tag }}
164+
ghcr.io/lsst-sqre/ltd-keeper:${{ steps.vars.outputs.tag }}
165+
cache-from: type=gha
166+
cache-to: type=gha,mode=max

Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ WORKDIR /home/appuser
5454
ENV PATH="/opt/venv/bin:$PATH"
5555

5656
COPY --from=install-image /opt/venv /opt/venv
57-
COPY uwsgi.ini bin migrations ./
57+
COPY bin uwsgi.ini ./
58+
ADD migrations ./migrations
5859

5960
# Switch to non-root user
6061
USER appuser
6162

6263
EXPOSE 3031
6364

64-
CMD ["uwsgi", "uwsgi.ini"]
65+
ENV FLASK_APP="keeper"
66+
67+
CMD ["./start-api.bash"]

bin/docker-tag.sh

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/bin/bash
22

3-
# Determine the tag for Docker images. Takes the Git ref as its only
4-
# argument.
3+
# Determine the tag for Docker images based on GitHub Actions environment
4+
# variables.
55

66
set -eo pipefail
77

8-
if [ -z "$1" ]; then
9-
echo 'Usage: scripts/docker-tag.sh $GITHUB_REF' >&2
10-
exit 1
8+
if [ -n "$GITHUB_HEAD_REF" ]; then
9+
# For pull requests
10+
echo ${GITHUB_HEAD_REF} | sed -E 's,/,-,g'
11+
else
12+
# For push events
13+
echo ${GITHUB_REF} | sed -E 's,refs/(heads|tags)/,,' | sed -E 's,/,-,g'
1114
fi
12-
13-
echo "$1" | sed -E 's,refs/(heads|tags)/,,' | sed -E 's,/,-,g'

bin/install-base-packages.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ apt-get -y upgrade
2929
# Install system packages
3030
# - build-essentiall needed for uwsgi
3131
# - git needed for setuptools_scm
32-
apt-get -y install --no-install-recommends git build-essential
32+
apt-get -y install --no-install-recommends git build-essential redis-server dnsutils wget
3333

3434
# Delete cached files we don't need anymore:
3535
apt-get clean

bin/start-api.bash

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
echo $PATH
6+
pwd
7+
ls migrations
8+
9+
flask createdb migrations/alembic.ini
10+
flask init
11+
uwsgi uwsgi.ini

keeper/cli.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from __future__ import annotations
88

9-
import os
109
from typing import TYPE_CHECKING
1110

1211
import alembic
@@ -39,15 +38,16 @@ def add_app_commands(app: Flask) -> None:
3938

4039

4140
@click.command("createdb")
41+
@click.argument("alembicconf")
4242
@with_appcontext
43-
def createdb_command() -> None:
43+
def createdb_command(alembicconf: str) -> None:
4444
"""Deploy the current schema in a new database.
4545
4646
This database is 'stamped' as having the current alembic schema version.
4747
4848
Normally, in a new installation, run::
4949
50-
flask createdb
50+
flask createdb migrations/alembic.ini
5151
flask init
5252
5353
This creates the tables and an initial user.
@@ -57,10 +57,7 @@ def createdb_command() -> None:
5757
db.create_all()
5858

5959
# stamp tables with latest schema version
60-
config_path = os.path.abspath(
61-
os.path.join(os.path.dirname(__file__), "..", "migrations/alembic.ini")
62-
)
63-
alembic_cfg = alembic.config.Config(config_path)
60+
alembic_cfg = alembic.config.Config(alembicconf)
6461
alembic.command.stamp(alembic_cfg, "head")
6562

6663

manifests/base/keeper-cm.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: ltd-keeper
5+
data:
6+
LTD_KEEPER_PROFILE: 'production'
7+
LTD_KEEPER_URL_SCHEME: 'https'
8+
LTD_KEEPER_BOOTSTRAP_USER: 'admin'
9+
LTD_KEEPER_DB_URL: ''
10+
REDIS_URL: ''
11+
LTD_KEEPER_ENABLE_V1: '1'
12+
LTD_KEEPER_ENABLE_V2: '1'
13+
LTD_KEEPER_PROXY_FIX: '0'
14+
LTD_KEEPER_X_FOR: '1'
15+
LTD_KEEPER_X_PROTO: '1'
16+
LTD_KEEPER_X_HOST: '1'
17+
LTD_KEEPER_X_PORT: '0'
18+
LTD_KEEPER_X_PREFIX: '0'
19+
LTD_KEEPER_ENABLE_TASKS: '0'

manifests/base/keeper-deployment.yaml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: ltd-keeper-api
6+
spec:
7+
replicas: 1
8+
selector:
9+
matchLabels:
10+
name: ltd-keeper-api
11+
template:
12+
metadata:
13+
labels:
14+
name: ltd-keeper-api
15+
spec:
16+
containers:
17+
- name: app
18+
imagePullPolicy: 'Always'
19+
image: 'ghcr.io/lsst-sqre/ltd-keeper:latest'
20+
ports:
21+
- containerPort: 3031
22+
name: api
23+
envFrom:
24+
- configMapRef:
25+
name: ltd-keeper
26+
27+
---
28+
# Deployment of celery workers for keeper
29+
apiVersion: apps/v1
30+
kind: Deployment
31+
metadata:
32+
name: ltd-keeper-worker
33+
spec:
34+
replicas: 1
35+
selector:
36+
matchLabels:
37+
name: ltd-keeper-worker
38+
template:
39+
metadata:
40+
labels:
41+
name: ltd-keeper-worker
42+
spec:
43+
containers:
44+
- name: app
45+
imagePullPolicy: 'Always'
46+
image: 'ghcr.io/lsst-sqre/ltd-keeper:latest'
47+
command: ['/bin/bash']
48+
args: ['-c', '/home/appuser/run-celery-worker.bash']
49+
envFrom:
50+
- configMapRef:
51+
name: ltd-keeper

manifests/base/keeper-service.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: ltd-keeper
5+
labels:
6+
name: ltd-keeper
7+
spec:
8+
ports:
9+
- name: ltd-keeper-http
10+
protocol: TCP
11+
port: 8080
12+
targetPort: api
13+
selector:
14+
name: ltd-keeper-api

manifests/kustomization.yaml manifests/base/kustomization.yaml

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ kind: Kustomization
33

44
resources:
55
- keeper-cm.yaml
6-
- redis-deployment.yaml
7-
- redis-service.yaml
86
- keeper-deployment.yaml
97
- keeper-service.yaml
108

119
images:
12-
- name: lsstsqre/ltd-keeper
13-
newTag: 1.20.3
10+
- name: 'lsstsqre/ltd-keeper:latest'
11+
newTag: u-jsickcodes-deploy-2-0

manifests/keeper-cm.yaml

-12
This file was deleted.

0 commit comments

Comments
 (0)