From da16b063484eae412916f7551c53b40070100fcb Mon Sep 17 00:00:00 2001 From: Harry Brundage Date: Sat, 4 May 2024 17:55:40 -0400 Subject: [PATCH] Build dateilager within the dockerfile using the nix environment This switches the build process to: - build DL within the dockerfile for repeatable builds, instead of copying in from outside - use the nix environment to setup the env for the build, so it's the same go version / protoc version etc etc in and outside of docker - use a multistage docker build so we have slim containers with just the binary at the end I did all this because I was fighting to get a docker image built for linux_arm64, which is what orbstack needs to run the image locally in a k8s setup! It was annoying. This also adds linux_arm64 as a build target to the makefile, and teaches the dockerfile how to build the binary for the target architecture that the dockerfile is building for. Yeesh. --- .dockerignore | 9 +++++++ .github/actions/setup-env/action.yml | 6 +---- Dockerfile | 40 +++++++++++++++++++++------- Makefile | 23 +++++++--------- Readme.md | 14 ++++------ flake.nix | 24 ++++++++++++++++- internal/pb/fs.pb.go | 4 +-- internal/pb/fs_grpc.pb.go | 2 +- 8 files changed, 81 insertions(+), 41 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..752e9901 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +.direnv +Dockerfile +js +test +tmp +bin +input +node_modules \ No newline at end of file diff --git a/.github/actions/setup-env/action.yml b/.github/actions/setup-env/action.yml index bd073f12..dc7c1ace 100644 --- a/.github/actions/setup-env/action.yml +++ b/.github/actions/setup-env/action.yml @@ -46,8 +46,4 @@ runs: - name: Add Go binaries to PATH run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - shell: bash -l {0} - - - name: Install Go binaries - run: make install - shell: bash -l {0} + shell: bash -l {0} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2847fe02..3f55edbd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,34 @@ -FROM --platform=linux/amd64 registry.fedoraproject.org/fedora-minimal:40 +FROM nixos/nix:2.22.0 AS build-stage +ARG TARGETARCH -RUN microdnf install -y curl findutils gzip iputils less postgresql procps shadow-utils tar time which \ - && microdnf clean all +RUN tee -a /etc/nix/nix.conf <