use entrypoint

This commit is contained in:
Jim Clark
2023-05-18 00:48:57 -07:00
parent e504aafa11
commit 8587cdcd7c
4 changed files with 113 additions and 6 deletions

View File

@@ -1 +1,32 @@
pod-atomisthq-tools.docker
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
**/.DS_Store
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

View File

@@ -9,7 +9,6 @@ RUN \
--mount=type=cache,target=/root/.cache \
--mount=type=bind,target=/tmp/build \
<<EOF
ls -l /nix/store | wc
nix \
--extra-experimental-features "nix-command flakes" \
--extra-substituters "http://host.docker.internal?priority=10" \
@@ -26,4 +25,4 @@ WORKDIR /app
COPY --from=builder /tmp/nix-store-closure /nix/store
COPY --from=builder /tmp/output/ /app/
ENTRYPOINT ["/app/result/bin/babashka-pod-docker"]
ENTRYPOINT ["/app/result/bin/entrypoint"]

72
Dockerfile.init Normal file
View File

@@ -0,0 +1,72 @@
# syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
################################################################################
# Create a stage for building the application.
ARG GO_VERSION=1.19
FROM golang:${GO_VERSION} AS build
WORKDIR /src
# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds.
# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into
# the container.
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download -x
# Build the application.
# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds.
# Leverage a bind mount to the current directory to avoid having to copy the
# source code into the container.
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \
CGO_ENABLED=0 go build -o /bin/server .
################################################################################
# Create a new stage for running the application that contains the minimal
# runtime dependencies for the application. This often uses a different base
# image from the build stage where the necessary files are copied from the build
# stage.
#
# The example below uses the alpine image as the foundation for running the app.
# By specifying the "latest" tag, it will also use whatever happens to be the
# most recent version of that image when you build your Dockerfile. If
# reproducability is important, consider using a versioned tag
# (e.g., alpine:3.17.2) or SHA (e.g., alpine:sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff).
FROM alpine:latest AS final
# Install any runtime dependencies that are needed to run your application.
# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds.
RUN --mount=type=cache,target=/var/cache/apk \
apk --update add \
ca-certificates \
tzdata \
&& \
update-ca-certificates
# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser
USER appuser
# Copy the executable from the "build" stage.
COPY --from=build /bin/server /bin/
# Expose the port that the application listens on.
EXPOSE 3000
# What the container should run when it is started.
ENTRYPOINT [ "/bin/server" ]

View File

@@ -36,7 +36,7 @@
];
};
packages = rec {
default = pkgs.buildGoApplication {
app = pkgs.buildGoApplication {
pname = "babashka-pod-docker";
version = "0.0.1";
src = ./.;
@@ -49,11 +49,16 @@
name = "docker-pod";
tag = "latest";
config = {
Cmd = [ "${default}/bin/babashka-pod-docker" ];
Cmd = [ "${app}/bin/babashka-pod-docker" ];
};
};
default-linux = default.overrideAttrs (old: old // { GOOS = "linux"; GOARCH = "arm64"; });
default-linux = app.overrideAttrs (old: old // { GOOS = "linux"; GOARCH = "arm64"; });
default = pkgs.writeShellScriptBin "entrypoint" ''
${app}/bin/babashka-pod-docker
'';
docker-arm64 = pkgs.dockerTools.buildImage {
name = "docker-pod";
tag = "latest";