diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f08a380 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +# Binaries for programs and plugins +bin/ +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Go workspace file +go.work + +# Helm resources +helm/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c565830 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,70 @@ +# Copyright 2023 Linode, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ARG TOOLCHAIN_VERSION=1.21 + +######################################################################################### +# Build +######################################################################################### + +# First stage: building the driver executable. +FROM docker.io/library/golang:${TOOLCHAIN_VERSION} as builder + +WORKDIR /work + +# Copy the Go Modules manifests. +COPY go.mod go.mod +COPY go.sum go.sum + +# Cache dep before building and copying source so that we don't need to re-download as +# much and so that source changes don't invalidate our downloaded layer. +RUN go mod download + +# Copy the go source. +COPY cmd/ cmd/ +COPY internal/ internal/ +COPY pkg/ pkg/ +COPY Makefile Makefile + +# Explicitly set the version, so the make won't try to get it (and fail). +ENV VERSION="builder" + +# Build. +RUN make build + +######################################################################################### +# Runtime +######################################################################################### + +# Second stage: building final environment for running the executable. +FROM gcr.io/distroless/static-debian11:latest AS runtime + +COPY --from=builder /work/bin/linode-cosi-driver /usr/bin/linode-cosi-driver + +# Set volume mount point for app socket. +VOLUME [ "/var/lib/cosi" ] + +# Disable healthcheck. +HEALTHCHECK NONE + +# Add labels +LABEL name="linode-cosi-driver" +LABEL description="COSI Driver for Linode Object Storage" +LABEL vendor="Linode, LLC" +LABEL license="Apache-2.0" +LABEL maintainers="Linode COSI Driver Authors" + +# Set the entrypoint. +ENTRYPOINT [ "/usr/bin/linode-cosi-driver" ] +CMD []