diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7e094a7f..dd5e4d28 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,18 +8,24 @@ on: jobs: goreleaser: - name: 'Build and release packages' + name: "Build and release packages" runs-on: ubuntu-latest permissions: id-token: write # For cosign packages: write # For GHCR - contents: read # Not required for public repositories, but for clarity + contents: read # Not required for public repositories, but for clarity steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Set up Go uses: actions/setup-go@v5 with: @@ -37,7 +43,7 @@ jobs: echo "${GPG_PRIVATE_KEY}" > "${GPG_KEY_FILE}" echo "GPG_KEY_FILE=${GPG_KEY_FILE}" >> "${GITHUB_ENV}" env: - GPG_TTY: /dev/ttys000 # Set the GPG_TTY to avoid issues with pinentry + GPG_TTY: /dev/ttys000 # Set the GPG_TTY to avoid issues with pinentry GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} @@ -65,22 +71,6 @@ jobs: GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }} - docker-ghcr: - name: 'Build and release docker image to github container registry' - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: @@ -88,39 +78,57 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push docker image - uses: docker/build-push-action@v6 - with: - push: true - tags: ghcr.io/tofuutils/tenv:${{ github.ref_name }}, ghcr.io/tofuutils/tenv:latest - - docker-dockerhub: - name: 'Build and release docker image to dockerhub' - runs-on: ubuntu-latest - env: - registry_url: "registry.hub.docker.com" - image_repo: "tofuutils/tenv" - permissions: - contents: read - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - name: Push docker image to GitHub Container Registry + env: + docker_registry: "ghcr.io" + run: | + version=${GITHUB_REF#refs/*/v} + IFS='.' read -ra version_arr <<< "${version}" + + architectures=("amd64" "arm64" "arm" "386") + versions=("latest", "${version_arr[0]}.${version_arr[1]}", "${version}") + + for arch in "${architectures[@]}"; do + for version in "${versions[@]}"; do + IMAGE="${docker_registry}/tofuutils/tenv:${VERSION}-${ARCH}" + echo "Pushing ${IMAGE}..." + docker push ${IMAGE} + if [ ${?} -ne 0 ]; then + echo "Failed to push ${IMAGE}" + exit 1 + fi + done + done + + echo "All images pushed successfully to ${docker_registry}!" - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: - registry: ${{ env.registry_url }} + registry: registry.hub.docker.com username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Build and push docker image - uses: docker/build-push-action@v6 - with: - push: true - tags: ${{ env.registry_url }}/${{ env.image_repo }}:latest, ${{ env.registry_url }}/${{ env.image_repo }}:${{ github.ref_name }} + - name: Push docker image to DockerHub + env: + docker_registry: "registry.hub.docker.com" + run: | + version=${GITHUB_REF#refs/*/v} + IFS='.' read -ra version_arr <<< "${version}" + + architectures=("amd64" "arm64" "arm" "386") + versions=("latest", "${version_arr[0]}.${version_arr[1]}", "${version}") + + for arch in "${architectures[@]}"; do + for version in "${versions[@]}"; do + IMAGE="${docker_registry}/tofuutils/tenv:${VERSION}-${ARCH}" + echo "Pushing ${IMAGE}..." + docker push ${IMAGE} + if [ ${?} -ne 0 ]; then + echo "Failed to push ${IMAGE}" + exit 1 + fi + done + done + + echo "All images pushed successfully to ${docker_registry}!" diff --git a/.goreleaser.yml b/.goreleaser.yml index a4250cb9..153a03ed 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -189,6 +189,125 @@ builds: - goos: solaris goarch: arm64 +dockers: + - use: buildx + goarch: amd64 + build_flag_templates: + - "--pull" + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.vendor=tofuutils" + - "--label=org.opencontainers.image.description=tenv {{ .Version }}" + - "--label=org.opencontainers.image.url=https://github.com/tofuutils/tenv" + - "--label=org.opencontainers.image.documentation=https://github.com/tofuutils/tenv/blob/main/README.md" + - "--label=org.opencontainers.image.source=https://github.com/tofuutils/tenv" + - "--label=org.opencontainers.image.licenses=Apache-2.0" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}' + image_templates: + - "ghcr.io/tofuutils/tenv:{{ .Version }}-amd64" + + - use: buildx + goarch: arm64 + build_flag_templates: + - "--pull" + - "--platform=linux/arm64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.vendor=tofuutils" + - "--label=org.opencontainers.image.description=tenv {{ .Version }}" + - "--label=org.opencontainers.image.url=https://github.com/tofuutils/tenv" + - "--label=org.opencontainers.image.documentation=https://github.com/tofuutils/tenv/blob/main/README.md" + - "--label=org.opencontainers.image.source=https://github.com/tofuutils/tenv" + - "--label=org.opencontainers.image.licenses=Apache-2.0" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}' + image_templates: + - "ghcr.io/tofuutils/tenv:{{ .Version }}-arm64" + + - use: buildx + goarch: arm + build_flag_templates: + - "--pull" + - "--platform=linux/arm" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.vendor=tofuutils" + - "--label=org.opencontainers.image.description=tenv {{ .Version }}" + - "--label=org.opencontainers.image.url=https://github.com/tofuutils/tenv" + - "--label=org.opencontainers.image.documentation=https://github.com/tofuutils/tenv/blob/main/README.md" + - "--label=org.opencontainers.image.source=https://github.com/tofuutils/tenv" + - "--label=org.opencontainers.image.licenses=Apache-2.0" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}' + image_templates: + - "ghcr.io/tofuutils/tenv:{{ .Version }}-arm" + + - use: buildx + goarch: "386" + build_flag_templates: + - "--pull" + - "--platform=linux/386" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.vendor=tofuutils" + - "--label=org.opencontainers.image.description=tenv {{ .Version }}" + - "--label=org.opencontainers.image.url=https://github.com/tofuutils/tenv" + - "--label=org.opencontainers.image.documentation=https://github.com/tofuutils/tenv/blob/main/README.md" + - "--label=org.opencontainers.image.source=https://github.com/tofuutils/tenv" + - "--label=org.opencontainers.image.licenses=Apache-2.0" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - '--label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}' + image_templates: + - "ghcr.io/tofuutils/tenv:{{ .Version }}-386" + +docker_manifests: + - name_template: ghcr.io/tofuutils/tenv:{{ .Version }} + 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 + 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 + 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 + - 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 + +docker_signs: + - artifacts: all + args: + [ + "sign", + "--oidc-issuer=https://token.actions.githubusercontent.com", + "${artifact}@${digest}", + "--yes", + ] archives: - format: tar.gz @@ -292,14 +411,14 @@ snapcrafts: publish: true summary: OpenTofu, Terraform, Terragrunt, and Atmos version manager, written in Go. description: | - tenv is a versatile version manager for OpenTofu, Terraform, Terragrunt and Atmos, written in Go. - Our tool simplifies the complexity of handling different versions of these powerful tools, - ensuring developers and DevOps professionals + tenv is a versatile version manager for OpenTofu, Terraform, Terragrunt and Atmos, written in Go. + Our tool simplifies the complexity of handling different versions of these powerful tools, + ensuring developers and DevOps professionals can focus on what matters most - building and deploying efficiently. - disable: 'false' + disable: "false" channel_templates: - - 'latest/stable' - grade: 'stable' + - "latest/stable" + grade: "stable" confinement: strict license: Apache-2.0 base: core22 @@ -307,27 +426,27 @@ snapcrafts: tenv: plugs: ["home", "network", "network-bind"] command: tenv - aliases: [ tenv ] + aliases: [tenv] tofu: plugs: ["home", "network", "network-bind"] command: tofu - aliases: [ tofu ] + aliases: [tofu] terraform: plugs: ["home", "network", "network-bind"] command: terraform - aliases: [ terraform ] + aliases: [terraform] terragrunt: plugs: ["home", "network", "network-bind"] command: terragrunt - aliases: [ terragrunt ] + aliases: [terragrunt] tf: plugs: ["home", "network", "network-bind"] command: tf - aliases: [ tf ] + aliases: [tf] atmos: plugs: ["home", "network", "network-bind"] command: atmos - aliases: [ atmos ] + aliases: [atmos] aurs: - name: tenv-bin @@ -381,7 +500,7 @@ aurs: # license install -Dm 0644 "LICENSE" "${pkgdir}/usr/share/licenses/tenv/LICENSE" install -Dm 0644 "LICENSE" "${pkgdir}/usr/share/doc/tenv/LICENSE" - + # readme install -Dm 0644 "README.md" "${pkgdir}/usr/share/doc/tenv/README.md" @@ -389,7 +508,7 @@ aurs: mkdir -p "${pkgdir}/usr/share/bash-completion/completions/" mkdir -p "${pkgdir}/usr/share/zsh/site-functions/" mkdir -p "${pkgdir}/usr/share/fish/vendor_completions.d/" - + for i in bash fish zsh; do ./tenv completion $i > ./tenv.$i done @@ -408,7 +527,6 @@ aurs: url_template: "https://github.com/tofuutils/tenv/releases/download/{{ .Tag }}/{{ .ArtifactName }}" directory: "." - # chocolateys: # - name: tenv # # Empty means all IDs. diff --git a/Dockerfile b/Dockerfile index 1df9cf47..34875fc0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,41 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. # -FROM golang:1.21 AS builder +FROM alpine:3.20 +LABEL maintainer="TofuUtils Core Team" -ENV CGO_ENABLED=0 \ - GOOS=linux \ - GOARCH=amd64 \ - GIT_TERMINAL_PROMPT=1 +RUN apk add --no-cache git bash openssh -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/ +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 -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 gcr.io/distroless/static:nonroot -COPY --from=builder go/src/github.com/tofuutils/tenv/atmos /app/ -COPY --from=builder go/src/github.com/tofuutils/tenv/tenv /app/ -COPY --from=builder go/src/github.com/tofuutils/tenv/terraform /app/ -COPY --from=builder go/src/github.com/tofuutils/tenv/terragrunt /app/ -COPY --from=builder go/src/github.com/tofuutils/tenv/tf /app/ -COPY --from=builder go/src/github.com/tofuutils/tenv/tofu /app/ -WORKDIR /app -ENTRYPOINT ["/app/tenv"] \ No newline at end of file +ENTRYPOINT ["/usr/local/bin/tenv"]