diff --git a/Dockerfile.base b/Dockerfile.base deleted file mode 100644 index 1a674ad..0000000 --- a/Dockerfile.base +++ /dev/null @@ -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/... diff --git a/Dockerfile.prod b/Dockerfile.prod index b5cf261..4f186e4 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -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/ diff --git a/Dockerfile.test b/Dockerfile.test index 0aa8dd4..b672649 100644 --- a/Dockerfile.test +++ b/Dockerfile.test @@ -1,4 +1,3 @@ -ARG BASE_IMAGE FROM alpine:3.20.2 RUN apk update && apk add curl openssh && mkdir /test WORKDIR /test diff --git a/Makefile b/Makefile index fc12ca9..27085cf 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/compose.yaml b/compose.yaml index de7a478..dea14e1 100644 --- a/compose.yaml +++ b/compose.yaml @@ -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