Reverted back to multi-stage build. Previous change of extracting baser image was not needed since the test container is a plain alpione container with a few additional packages.

This commit is contained in:
Erik Brakkee 2024-08-29 12:42:26 +02:00
parent 69b58976ae
commit 51d46ee07d
5 changed files with 21 additions and 39 deletions

View File

@ -1,18 +0,0 @@
FROM alpine:3.20.2
RUN apk update && apk add go curl
RUN mkdir -p /opt/converge/bin
# if templ cannot be obtained: quick fix, remove this statement and run make, then build the image.
RUN curl -L https://github.com/a-h/templ/releases/download/v0.2.747/templ_Linux_x86_64.tar.gz -o templ.tar.gz && \
tar xvzf templ.tar.gz templ && \
chmod 755 templ && \
mv templ /bin
COPY cmd pkg static go.mod go.sum /opt/converge/
WORKDIR /opt/converge
ENV GOTOOLCHAIN=auto
RUN go mod download
COPY . /opt/converge/
RUN templ generate
RUN go build -ldflags "-linkmode 'external' -extldflags '-static'" -o bin ./cmd/...
RUN GOOS=windows GOARCH=amd64 go build -o bin ./cmd/...

View File

@ -1,6 +1,22 @@
FROM alpine:3.20.2 as builder
RUN apk update && apk add go curl
RUN mkdir -p /opt/converge/bin
# if templ cannot be obtained: quick fix, remove this statement and run make, then build the image.
RUN curl -L https://github.com/a-h/templ/releases/download/v0.2.747/templ_Linux_x86_64.tar.gz -o templ.tar.gz && \
tar xvzf templ.tar.gz templ && \
chmod 755 templ && \
mv templ /bin
COPY cmd pkg static go.mod go.sum /opt/converge/
WORKDIR /opt/converge
ENV GOTOOLCHAIN=auto
RUN go mod download
COPY . /opt/converge/
RUN templ generate
RUN go build -ldflags "-linkmode 'external' -extldflags '-static'" -o bin ./cmd/...
RUN GOOS=windows GOARCH=amd64 go build -o bin ./cmd/...
ARG BASE_IMAGE
FROM ${BASE_IMAGE} as builder
FROM scratch
COPY --from=builder /opt/converge/bin/converge /opt/converge/bin/

View File

@ -1,4 +1,3 @@
ARG BASE_IMAGE
FROM alpine:3.20.2
RUN apk update && apk add curl openssh && mkdir /test
WORKDIR /test

View File

@ -37,10 +37,7 @@ icons: static/icons/.downloaded
all: icons build buildwin
images:
docker compose build converge-builder
docker compose build converge
docker compose build converge-tester
docker compose --profile build build
push: images
docker compose push converge
docker compose push converge-tester
docker compose --profile build push

View File

@ -1,21 +1,11 @@
services:
converge-builder:
image: $REGISTRY/converge-builder:1.0.0
build:
context: .
dockerfile: Dockerfile.base
profiles:
- build_only
converge:
image: $REGISTRY/converge:1.0.0
build:
context: .
dockerfile: Dockerfile.prod
args:
BASE_IMAGE: $REGISTRY/converge-builder:1.0.0
ports:
- 8000:8000
@ -25,8 +15,6 @@ services:
build:
context: .
dockerfile: Dockerfile.test
args:
BASE_IMAGE: $REGISTRY/converge-builder:1.0.0
profiles:
- build_only
- build