Skip to content

Commit d7b8c43

Browse files
committed
BE: Build Docker cnt in GH action
1 parent 416a9b4 commit d7b8c43

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Build docker image
2+
3+
on:
4+
push:
5+
pull_request:
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
-
12+
name: Set up Docker Buildx
13+
uses: docker/setup-buildx-action@v3
14+
-
15+
uses: docker/build-push-action@v6
16+
with:
17+
context: "{{defaultContext}}:backend"
18+
push: false
19+
load: true
20+
file: projectify-backend.Dockerfile
21+
cache-from: type=gha
22+
cache-to: type=gha,mode=max

backend/flake.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@
7878
groups = [ ];
7979
outputs = [ "out" "static" ];
8080
postInstall = ''
81-
mkdir -p $out/bin
81+
mkdir -p $out/bin $out/etc
8282
cp manage.py "$out/bin"
8383
84+
cp gunicorn.conf.py gunicorn-error.log $out/etc/
85+
8486
mkdir -p $static
8587
env \
8688
DJANGO_SETTINGS_MODULE=projectify.settings.collect_static \

backend/projectify-backend.Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM docker.io/nixos/nix:2.22.3 as builder
2+
3+
COPY . /tmp/build
4+
WORKDIR /tmp/build
5+
6+
# https://marcopolo.io/code/nix-and-small-containers/
7+
# https://mitchellh.com/writing/nix-with-dockerfiles
8+
RUN echo "experimental-features = nix-command flakes" > /etc/nix/nix.conf \
9+
&& nix build .#projectify-backend .#projectify-backend.static \
10+
&& cp -a "$(nix-store -qR result/)" /tmp/nix-store-closure
11+
12+
FROM scratch
13+
WORKDIR /app
14+
COPY --from=builder /tmp/nix-store-closure /nix/store
15+
COPY --from=builder /tmp/build/result /app
16+
COPY --from=builder /tmp/build/result-1-static /static
17+
ENV STATIC_ROOT=/static
18+
19+
CMD ["gunicorn", "--config", "/app/etc/gunicorn.conf.py", "--log-config", "/app/etc/gunicorn-error.log"]

0 commit comments

Comments
 (0)