Skip to content

Commit a79807f

Browse files
nix -> Dockerfile
1 parent b1622b3 commit a79807f

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

.github/workflows/build-and-deploy.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ jobs:
1313
- uses: actions/checkout@v4
1414
with:
1515
fetch-depth: 0
16-
- uses: DeterminateSystems/nix-installer-action@main
17-
- uses: DeterminateSystems/flakehub-cache-action@main
18-
- name: Build and load image
19-
run: docker load <$(nix build --extra-experimental-features "nix-command flakes" --print-out-paths --no-link .#packages.x86_64-linux.docker)
16+
- name: Build docker image
17+
run: docker build -t $IMAGE_NAME .
2018
- name: Log in to registry
2119
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
2220
- name: Push image

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Nix builder
2+
FROM nixos/nix:latest AS builder
3+
4+
# Copy our source and setup our working dir.
5+
COPY . /tmp/build
6+
WORKDIR /tmp/build
7+
8+
# Build our Nix environment
9+
RUN nix \
10+
--extra-experimental-features "nix-command flakes" \
11+
--option filter-syscalls false \
12+
build
13+
14+
# Copy the Nix store closure into a directory. The Nix store closure is the
15+
# entire set of Nix store values that we need for our build.
16+
RUN mkdir /tmp/nix-store-closure
17+
RUN cp -R $(nix-store -qR result/) /tmp/nix-store-closure
18+
19+
# we also need davfs2 and I'm struggling to get it to work in a pure nix environment
20+
# this step means we likely have 2 versions (nix store and debian) versions of lots of things
21+
FROM debian:bullseye-slim
22+
23+
RUN apt-get update && apt-get install -y davfs2
24+
RUN ln -s /proc/mounts /etc/mtab
25+
26+
WORKDIR /app
27+
28+
# Copy /nix/store
29+
COPY --from=builder /tmp/nix-store-closure /nix/store
30+
COPY --from=builder /tmp/build/result /app
31+
ENTRYPOINT ["/app/bin/webdav"]

flake.nix

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,6 @@
2828
webdavplugin = callPackage ./. {
2929
inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
3030
};
31-
32-
docker = pkgs.dockerTools.buildImage {
33-
name = "webdavplugin";
34-
tag = "latest";
35-
contents = pkgs.buildEnv {
36-
name = "image-root";
37-
paths = with pkgs; [
38-
mount
39-
davfs2
40-
];
41-
};
42-
# https://nixos.org/manual/nixpkgs/stable/#ssec-pkgs-dockerTools-shadowSetup
43-
runAsRoot = ''
44-
${pkgs.dockerTools.shadowSetup}
45-
groupadd -r davfs2
46-
useradd -r -g davfs2 davfs2
47-
ln -s /proc/mounts /etc/mtab # davfs2 needs this
48-
mkdir -p /var/cache/davfs2
49-
chmod 0600 /etc/davfs2/secrets # reset permissions
50-
'';
51-
config.Entrypoint = ["${webdavplugin}/bin/webdav"];
52-
};
5331
};
5432
devShells.default = callPackage ./shell.nix {
5533
inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix;

0 commit comments

Comments
 (0)