Skip to content

Commit 7084606

Browse files
committed
refactor: merge into single multi stage dockerfile
1 parent 1f41985 commit 7084606

File tree

5 files changed

+47
-41
lines changed

5 files changed

+47
-41
lines changed

Dockerfile

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# A base ocfweb Dockerfile containing the code and dependencies.
22
# This doesn't run the website or the background worker; see Dockerfile.* for those.
3-
FROM docker.ocf.berkeley.edu/theocf/debian:bullseye
3+
FROM theocf/debian:bullseye-py AS base
44

55
RUN apt-get update \
66
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
@@ -51,3 +51,44 @@ ENV OCFWEB_TESTING 1
5151
WORKDIR /opt/ocfweb
5252

5353
CMD ["runsvdir", "/opt/ocfweb/services"]
54+
55+
##########
56+
# static #
57+
##########
58+
59+
FROM base AS static
60+
61+
RUN /opt/ocfweb/venv/bin/pysassc /opt/ocfweb/ocfweb/static/scss/site.scss /opt/ocfweb/ocfweb/static/scss/site.scss.css
62+
RUN find /opt/ocfweb/ocfweb/ \( -name '*.js' -o -name '*.css' \) -exec yui-compressor -o {} {} \;
63+
RUN mkdir /opt/ocfweb/static
64+
ENV OCFWEB_STATIC_ROOT /opt/ocfweb/static
65+
RUN /opt/ocfweb/venv/bin/python /opt/ocfweb/manage.py collectstatic --noinput
66+
67+
COPY services/static /opt/ocfweb/services/static
68+
RUN chown -R nobody:nogroup /opt/ocfweb/services
69+
70+
USER nobody
71+
72+
#######
73+
# web #
74+
#######
75+
76+
FROM base as web
77+
78+
COPY services/web /opt/ocfweb/services/
79+
RUN chown -R nobody:nogroup /opt/ocfweb/services
80+
81+
USER nobody
82+
83+
##########
84+
# worker #
85+
##########
86+
87+
FROM base as worker
88+
89+
COPY services/worker /opt/ocfweb/services/worker
90+
RUN chown -R nobody:nogroup /opt/ocfweb/services
91+
92+
USER nobody
93+
94+
# vim: ft=Dockerfile

Dockerfile.static.in

Lines changed: 0 additions & 14 deletions
This file was deleted.

Dockerfile.web.in

Lines changed: 0 additions & 8 deletions
This file was deleted.

Dockerfile.worker.in

Lines changed: 0 additions & 8 deletions
This file was deleted.

Makefile

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ RANDOM_PORT := $(shell expr $$(( 8000 + (`id -u` % 1000) )))
55
LISTEN_IP := 0.0.0.0
66
DOCKER_REPO ?= docker-push.ocf.berkeley.edu/
77
DOCKER_REVISION ?= testing-$(USER)
8-
DOCKER_TAG_BASE = ocfweb-base-$(USER)
98
DOCKER_TAG_WEB = $(DOCKER_REPO)ocfweb-web:$(DOCKER_REVISION)
109
DOCKER_TAG_WORKER = $(DOCKER_REPO)ocfweb-worker:$(DOCKER_REVISION)
1110
DOCKER_TAG_STATIC = $(DOCKER_REPO)ocfweb-static:$(DOCKER_REVISION)
@@ -20,17 +19,13 @@ test: venv mypy
2019
mypy: venv
2120
$(BIN)/mypy -p ocfweb
2221

23-
.PHONY: Dockerfile.%
24-
Dockerfile.%: Dockerfile.%.in
25-
sed 's/{tag}/$(DOCKER_TAG_BASE)/g' "$<" > "$@"
26-
2722
.PHONY: cook-image
28-
cook-image: Dockerfile.web Dockerfile.worker Dockerfile.static
23+
cook-image:
2924
$(eval OCFLIB_VERSION := ==$(shell curl https://pypi.org/pypi/ocflib/json | jq -r .info.version))
30-
docker build --pull --build-arg ocflib_version=$(OCFLIB_VERSION) -t $(DOCKER_TAG_BASE) .
31-
docker build -t $(DOCKER_TAG_WEB) -f Dockerfile.web .
32-
docker build -t $(DOCKER_TAG_WORKER) -f Dockerfile.worker .
33-
docker build -t $(DOCKER_TAG_STATIC) -f Dockerfile.static .
25+
docker build --pull --build-arg ocflib_version=$(OCFLIB_VERSION) --target base .
26+
docker build -t $(DOCKER_TAG_WEB) --target web .
27+
docker build -t $(DOCKER_TAG_WORKER) --target worker .
28+
docker build -t $(DOCKER_TAG_STATIC) --target static .
3429

3530
.PHONY: push-image
3631
push-image:

0 commit comments

Comments
 (0)