Skip to content

Commit 6a1c2c4

Browse files
committed
Add deployment infrastructure for GCP
1 parent 8d48fab commit 6a1c2c4

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Step 1/3: Base image
2+
FROM python:3.11-slim-bookworm as base
3+
RUN \
4+
--mount=type=cache,target=/var/cache/apt \
5+
apt-get update && apt-get upgrade -y && apt install curl -y
6+
7+
## Step 2/3: Build/Install app dependencies
8+
FROM base as builder
9+
# Allow statements and log messages to immediately appear in the Knative logs
10+
ENV PYTHONUNBUFFERED True
11+
12+
COPY pyproject.toml README.md /
13+
14+
RUN --mount=type=cache,target=/var/cache/apt apt install -y gcc git
15+
RUN --mount=type=cache,mode=0777,target=/root/.cache/pip \
16+
pip install --upgrade pip setuptools wheel && \
17+
pip install -e . && \
18+
mkdir -p /app/src
19+
20+
COPY tests/data /app/tests/data
21+
COPY src/simdec /app/src/simdec
22+
COPY app.py /app/app.py
23+
24+
# Step 3/3: Image
25+
FROM base as panel
26+
# Allow statements and log messages to immediately appear in the Knative logs
27+
ENV PYTHONUNBUFFERED True
28+
ENV PYTHONPATH=/app/src
29+
ENV PYTHONIOENCODING=utf-8
30+
ENV ENV=production
31+
ENV PORT=8080
32+
33+
ARG PANEL_TOKEN
34+
35+
COPY --from=builder /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
36+
COPY --from=builder /usr/local/bin/panel /usr/local/bin/panel
37+
COPY --from=builder /app/src /app/src
38+
COPY --from=builder /app/tests/data /app/tests/data
39+
COPY --from=builder /app/app.py /app/app.py
40+
41+
WORKDIR /app
42+
RUN useradd app && usermod -a -G app app
43+
USER app
44+
# Run the web service on container startup.
45+
CMD panel serve app.py --address 0.0.0.0 --port 8080 --allow-websocket-origin="*" --basic-auth PANEL_TOKEN --num-procs 2 --cookie-secret my_super_safe_cookie_secret

Makefile

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
.PHONY: help prepare doc test serve
1+
.PHONY: help prepare doc test serve build publish-production
22
.DEFAULT_GOAL := help
33
SHELL:=/bin/bash
44

5+
ifndef version
6+
override version = development
7+
endif
8+
9+
ifndef region
10+
override region = europe-north1
11+
endif
12+
13+
ifndef project
14+
override project = delta-entity-401706
15+
endif
16+
17+
ifndef PANEL_TOKEN
18+
# only for local dev, another token is used for deployment
19+
override PANEL_TOKEN = e41ea4c145bf13a60c8779c24356
20+
endif
21+
22+
523
# Add help text after each target name starting with '\#\#'
624
help: ## show this help
725
@echo -e "Help for this makefile\n"
@@ -11,6 +29,8 @@ help: ## show this help
1129
prepare: ## Install dependencies and pre-commit hook
1230
pip install -e ".[dev]"
1331
pre-commit install
32+
gcloud init
33+
gcloud auth configure-docker
1434

1535
doc: ## Build Sphinx documentation
1636
sphinx-build -b html docs docs/html
@@ -23,3 +43,36 @@ serve-dev: ## Serve Panel dashboard - Dev mode
2343

2444
serve: ## Serve Panel dashboard - Prod mode
2545
panel serve app.py
46+
47+
build:
48+
docker build -f ./Dockerfile \
49+
--platform linux/amd64 \
50+
--build-arg PANEL_TOKEN=$(PANEL_TOKEN) \
51+
--tag simdec-panel:$(version) \
52+
--pull \
53+
./.
54+
55+
run: build
56+
docker run --rm -it \
57+
--memory=1g \
58+
--cpuset-cpus=0 \
59+
-e ENV=development \
60+
-p "8080:8080" \
61+
simdec-panel:$(version)
62+
63+
publish-production: build
64+
docker tag simdec-panel:$(version) $(region)-docker.pkg.dev/$(project)/simdec-panel/simdec-panel:$(version)
65+
docker push $(region)-docker.pkg.dev/$(project)/simdec-panel/simdec-panel:$(version)
66+
67+
production: publish-production
68+
@echo "Deploying '$(version)'."
69+
gcloud run deploy simdec-panel \
70+
--concurrency=10 \
71+
--max-instances=1 \
72+
--region=$(region) \
73+
--port=8080 \
74+
--set-env-vars ENV=production \
75+
--allow-unauthenticated \
76+
--timeout=10 \
77+
--image=$(region)-docker.pkg.dev/$(project)/simdec-panel/simdec-panel:$(version) \
78+
--memory 1Gi

0 commit comments

Comments
 (0)