···11+# Stage 1: Build the Go binary using Just
22+FROM golang:1.20 AS builder
33+44+# Install Just in the builder stage
55+RUN apt-get update && apt-get install -y curl && \
66+ curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin/just
77+88+# Set the working directory in the container
99+WORKDIR /app
1010+1111+# Copy the go.mod and go.sum files first to cache the dependencies
1212+COPY go.mod go.sum ./
1313+1414+# Download dependencies
1515+RUN go mod download
1616+1717+# Copy the Justfile and source code
1818+COPY Justfile .
1919+COPY . .
2020+2121+# Build the Go binary using Just
2222+RUN just build
2323+2424+# Stage 2: Create a lightweight image with just the binary
2525+FROM alpine:latest
2626+2727+# Set the working directory in the container
2828+WORKDIR /app
2929+3030+# Copy the binary from the builder stage
3131+COPY --from=builder /app/myapp .
3232+3333+# Expose a port (optional)
3434+EXPOSE 8080
3535+3636+# Command to run the binary
3737+CMD ["./myapp"]
+11
Justfile
···1111 go mod tidy
1212 go build -v -ldflags="-X main.Version={{current_version}}" -o bin/server server/*.go
13131414+docker:
1515+ docker build -t notella:{{current_version}} .
1616+ docker tag notella:{{current_version}} notella:latest
1717+ docker tag notella:{{current_version}} harbor.k8s.inpt.fr/net7/notella:{{current_version}}
1818+ docker tag notella:{{current_version}} harbor.k8s.inpt.fr/net7/notella:latest
1919+ docker push notella:{{current_version}}
2020+ docker push notella:latest
2121+ docker push harbor.k8s.inpt.fr/net7/notella:{{current_version}}
2222+ docker push harbor.k8s.inpt.fr/net7/notella:latest
2323+2424+1425install:
1526 just build
1627 cp bin/server ~/.local/bin/notella