Skip to content

Commit

Permalink
feat: improve docker images build
Browse files Browse the repository at this point in the history
  • Loading branch information
kvendingoldo committed Jul 25, 2024
1 parent 1f22598 commit 4f06726
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 46 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ jobs:
for arch in "${architectures[@]}"; do
for version in "${versions[@]}"; do
IMAGE="${docker_registry}/tofuutils/tenv:${version}-${arch}"
echo "Pushing ${IMAGE}..."
echo "Pushing ${IMAGE} ..."
docker push ${IMAGE}
docker manifest push ${IMAGE}
if [ ${?} -ne 0 ]; then
echo "Failed to push ${IMAGE}"
exit 1
Expand Down Expand Up @@ -122,8 +125,11 @@ jobs:
for arch in "${architectures[@]}"; do
for version in "${versions[@]}"; do
IMAGE="${docker_registry}/tofuutils/tenv:${version}-${arch}"
echo "Pushing ${IMAGE}..."
echo "Pushing ${IMAGE} ..."
docker push ${IMAGE}
docker manifest push ${IMAGE}
if [ ${?} -ne 0 ]; then
echo "Failed to push ${IMAGE}"
exit 1
Expand Down
22 changes: 0 additions & 22 deletions .github/workflows/test.sh

This file was deleted.

65 changes: 49 additions & 16 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ builds:
dockers:
- use: buildx
goarch: amd64
dockerfile: Dockerfile.goreleaser
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
Expand All @@ -206,12 +207,17 @@ dockers:
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}'
image_templates:
- "ghcr.io/tofuutils/tenv:latest-amd64"
- "ghcr.io/tofuutils/tenv:{{ .Version }}-amd64"
- "ghcr.io/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-amd64"
- "registry.hub.docker.com/tofuutils/tenv:latest-amd64"
- "registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-amd64"
- "registry.hub.docker.com/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-amd64"
skip_push: true

- use: buildx
goarch: arm64
dockerfile: Dockerfile.goreleaser
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
Expand All @@ -226,12 +232,17 @@ dockers:
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}'
image_templates:
- "ghcr.io/tofuutils/tenv:latest-arm64"
- "ghcr.io/tofuutils/tenv:{{ .Version }}-arm64"
- "ghcr.io/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-arm64"
- "registry.hub.docker.com/tofuutils/tenv:latest-arm64"
- "registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-arm64"
- "registry.hub.docker.com/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-arm64"
skip_push: true

- use: buildx
goarch: arm
dockerfile: Dockerfile.goreleaser
build_flag_templates:
- "--pull"
- "--platform=linux/arm"
Expand All @@ -246,12 +257,17 @@ dockers:
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}'
image_templates:
- "ghcr.io/tofuutils/tenv:latest-arm"
- "ghcr.io/tofuutils/tenv:{{ .Version }}-arm"
- "ghcr.io/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-arm"
- "registry.hub.docker.com/tofuutils/tenv:latest-arm"
- "registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-arm"
- "registry.hub.docker.com/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-arm"
skip_push: true

- use: buildx
goarch: "386"
dockerfile: Dockerfile.goreleaser
build_flag_templates:
- "--pull"
- "--platform=linux/386"
Expand All @@ -266,8 +282,12 @@ dockers:
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}'
image_templates:
- "ghcr.io/tofuutils/tenv:latest-386"
- "ghcr.io/tofuutils/tenv:{{ .Version }}-386"
- "ghcr.io/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-386"
- "registry.hub.docker.com/tofuutils/tenv:latest-386"
- "registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-386"
- "registry.hub.docker.com/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-386"
skip_push: true

docker_manifests:
Expand All @@ -277,36 +297,49 @@ docker_manifests:
- ghcr.io/tofuutils/tenv:{{ .Version }}-arm64
- ghcr.io/tofuutils/tenv:{{ .Version }}-arm
- ghcr.io/tofuutils/tenv:{{ .Version }}-386
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-amd64
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-arm64
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-arm
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-386
skip_push: true

- name_template: ghcr.io/tofuutils/tenv:{{ .Major }}.{{ .Minor }}
image_templates:
- ghcr.io/tofuutils/tenv:{{ .Version }}-amd64
- ghcr.io/tofuutils/tenv:{{ .Version }}-arm64
- ghcr.io/tofuutils/tenv:{{ .Version }}-arm
- ghcr.io/tofuutils/tenv:{{ .Version }}-386
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-amd64
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-arm64
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-arm
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-386
- ghcr.io/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-amd64
- ghcr.io/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-arm64
- ghcr.io/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-arm
- ghcr.io/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-386
skip_push: true

- name_template: ghcr.io/tofuutils/tenv:latest
image_templates:
- ghcr.io/tofuutils/tenv:{{ .Version }}-amd64
- ghcr.io/tofuutils/tenv:{{ .Version }}-arm64
- ghcr.io/tofuutils/tenv:{{ .Version }}-arm
- ghcr.io/tofuutils/tenv:{{ .Version }}-386
- ghcr.io/tofuutils/tenv:latest-amd64
- ghcr.io/tofuutils/tenv:latest-arm64
- ghcr.io/tofuutils/tenv:latest-arm
- ghcr.io/tofuutils/tenv:latest-386
skip_push: true

- name_template: registry.hub.docker.com/tofuutils/tenv:{{ .Version }}
image_templates:
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-amd64
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-arm64
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-arm
- registry.hub.docker.com/tofuutils/tenv:{{ .Version }}-386
skip_push: true

- name_template: registry.hub.docker.com/tofuutils/tenv:{{ .Major }}.{{ .Minor }}
image_templates:
- registry.hub.docker.com/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-amd64
- registry.hub.docker.com/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-arm64
- registry.hub.docker.com/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-arm
- registry.hub.docker.com/tofuutils/tenv:{{ .Major }}.{{ .Minor }}-386
skip_push: true

- name_template: registry.hub.docker.com/tofuutils/tenv:latest
image_templates:
- registry.hub.docker.com/tofuutils/tenv:latest-amd64
- registry.hub.docker.com/tofuutils/tenv:latest-arm64
- registry.hub.docker.com/tofuutils/tenv:latest-arm
- registry.hub.docker.com/tofuutils/tenv:latest-386
skip_push: true


docker_signs:
- cmd: cosign
env:
Expand Down
41 changes: 35 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,45 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
FROM golang:1.21 AS builder

ENV CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
GIT_TERMINAL_PROMPT=1

COPY ./cmd ${GOPATH}/src/github.com/tofuutils/tenv/cmd
COPY ./config ${GOPATH}/src/github.com/tofuutils/tenv/config
COPY ./pkg ${GOPATH}/src/github.com/tofuutils/tenv/pkg
COPY ./versionmanager ${GOPATH}/src/github.com/tofuutils/tenv/versionmanager
COPY ./go.mod ./go.sum ${GOPATH}/src/github.com/tofuutils/tenv/

WORKDIR ${GOPATH}/src/github.com/tofuutils/tenv
RUN go get -u ./cmd/atmos \
&& go get -u ./cmd/tenv \
&& go get -u ./cmd/terraform \
&& go get -u ./cmd/terragrunt \
&& go get -u ./cmd/tf \
&& go get -u ./cmd/tofu \
&& go mod tidy

RUN go build -ldflags="-s -w" -o atmos ./cmd/atmos \
&& go build -ldflags="-s -w" -o tenv ./cmd/tenv \
&& go build -ldflags="-s -w" -o terraform ./cmd/terraform \
&& go build -ldflags="-s -w" -o terragrunt ./cmd/terragrunt \
&& go build -ldflags="-s -w" -o tf ./cmd/tf \
&& go build -ldflags="-s -w" -o tofu ./cmd/tofu

FROM alpine:3.20
LABEL maintainer="TofuUtils Core Team"

RUN apk add --no-cache git bash openssh

COPY atmos /usr/local/bin/atmos
COPY tenv /usr/local/bin/tenv
COPY terraform /usr/local/bin/terraform
COPY terragrunt /usr/local/bin/terragrunt
COPY tf /usr/local/bin/tf
COPY tofu /usr/local/bin/tofu
COPY --from=builder go/src/github.com/tofuutils/tenv/atmos /usr/local/bin/atmos
COPY --from=builder go/src/github.com/tofuutils/tenv/tenv /usr/local/bin/tenv
COPY --from=builder go/src/github.com/tofuutils/tenv/terraform /usr/local/bin/terraform
COPY --from=builder go/src/github.com/tofuutils/tenv/terragrunt /usr/local/bin/terragrunt
COPY --from=builder go/src/github.com/tofuutils/tenv/tf /usr/local/bin/tf
COPY --from=builder go/src/github.com/tofuutils/tenv/tofu /usr/local/bin/tofu

ENTRYPOINT ["/usr/local/bin/tenv"]
28 changes: 28 additions & 0 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2024 tofuutils authors.
#
# 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.
#
FROM alpine:3.20
LABEL maintainer="TofuUtils Core Team"

RUN apk add --no-cache git bash openssh

COPY atmos /usr/local/bin/atmos
COPY tenv /usr/local/bin/tenv
COPY terraform /usr/local/bin/terraform
COPY terragrunt /usr/local/bin/terragrunt
COPY tf /usr/local/bin/tf
COPY tofu /usr/local/bin/tofu

ENTRYPOINT ["/usr/local/bin/tenv"]

0 comments on commit 4f06726

Please sign in to comment.