From e240ea480d54890e12f8b6bda498864a9d7e9cfe Mon Sep 17 00:00:00 2001 From: wesleymccollam Date: Wed, 8 Jan 2025 14:43:24 -0500 Subject: [PATCH 1/5] Docker image support using GoReleaser --- .github/workflows/goreleaser.yaml | 9 ++++++++ .goreleaser.yaml | 34 +++++++++++++++++++++++++++--- Dockerfile | 35 +++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/goreleaser.yaml b/.github/workflows/goreleaser.yaml index c67e288e..28f48095 100644 --- a/.github/workflows/goreleaser.yaml +++ b/.github/workflows/goreleaser.yaml @@ -21,6 +21,15 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 - name: Run GoReleaser uses: goreleaser/goreleaser-action@v6 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index f357cb85..ee09c5ec 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -19,7 +19,7 @@ builds: # Default: '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser'. # Templates: allowed. ldflags: - - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' + - "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}" # GOOS list to build for. # For more info refer to: https://golang.org/doc/install/source#environment @@ -96,8 +96,7 @@ checksum: disable: false brews: - - - # Git author used to commit to the repository. + - # Git author used to commit to the repository. commit_author: name: goreleaserbot email: bot@goreleaser.com @@ -158,3 +157,32 @@ brews: name: homebrew-tap token: "{{ .Env.GORELEASER_HOMEBREW_TAP_GITHUB_PAT}}" + +dockers: + - image_templates: + - &amd64_image "pingidentity/pingcli:{{ .Version }}-amd64" + use: buildx + dockerfile: Dockerfile + goarch: amd64 + build_flag_templates: + - "--platform=linux/arm64" + - "--build-arg=RELEASE_VERSION={{ .Version }}" + - image_templates: + - &arm64_image "pingidentity/pingcli:{{ .Version }}-arm64v8" + use: buildx + dockerfile: Dockerfile + goarm: "8" + build_flag_templates: + - "--platform=linux/arm64" + - "--build-arg=RELEASE_VERSION={{ .Version }}" + +docker_manifests: + - id: pingcli + - name_template: "pingidentity/pingcli:latest" + image_templates: + - *amd64_image + - *arm64_image + - name_template: "pingidentity/pingcli:{{ .Version }}" + image_templates: + - *amd64_image + - *arm64_image diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..14f32293 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# Use the official Go image as the base for building +FROM golang:1.23 as builder + +# GitHub tag +ARG RELEASE_VERSION + +# Set the working directory +WORKDIR /app + +# Download the source code from GitHub Releases +RUN curl -L https://github.com/pingidentity/pingcli/archive/refs/tags/v${RELEASE_VERSION}.tar.gz | tar xz --strip-components=1 + +# Build the pingcli binary (ensure static build) +RUN CGO_ENABLED=0 go mod tidy && CGO_ENABLED=0 go build -o /pingcli + +# Debugging step: Check if the binary exists +RUN ls -al /pingcli + +# Use Alpine as the runtime image +FROM alpine:latest + +# Copy the binary from the builder stage +COPY --from=builder /pingcli /usr/local/bin/pingcli + +# Set permissions for the binary +RUN chmod +x /usr/local/bin/pingcli + +# Debugging step: Verify binary is in place +RUN ls -al /usr/local/bin/pingcli + +# Set the entry point +ENTRYPOINT ["pingcli"] + +# Allow subcommands +CMD [] From 96625d1a3a6c2abc67cc5eb5d27f2823e6e8383d Mon Sep 17 00:00:00 2001 From: wesleymccollam Date: Wed, 8 Jan 2025 14:46:25 -0500 Subject: [PATCH 2/5] rename docker username secret variable --- .github/workflows/goreleaser.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/goreleaser.yaml b/.github/workflows/goreleaser.yaml index 28f48095..3b7b019f 100644 --- a/.github/workflows/goreleaser.yaml +++ b/.github/workflows/goreleaser.yaml @@ -25,7 +25,7 @@ jobs: name: Login to Docker Hub uses: docker/login-action@v3 with: - username: ${{ secrets.USERNAME }} + username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} - name: Set up QEMU From 32478f2c218396c4b4c0c74a5d6a09b60a23c43e Mon Sep 17 00:00:00 2001 From: wesleymccollam Date: Wed, 8 Jan 2025 14:48:21 -0500 Subject: [PATCH 3/5] rename docker access token secret variable name --- .github/workflows/goreleaser.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/goreleaser.yaml b/.github/workflows/goreleaser.yaml index 3b7b019f..c4223755 100644 --- a/.github/workflows/goreleaser.yaml +++ b/.github/workflows/goreleaser.yaml @@ -26,7 +26,7 @@ jobs: uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} + password: ${{ secrets.DOCKER_ACCESS_TOKEN }} - name: Set up QEMU uses: docker/setup-qemu-action@v3 From 04417373b565d6256b53d5fcb78eed23b7782595 Mon Sep 17 00:00:00 2001 From: wesleymccollam Date: Fri, 10 Jan 2025 15:32:27 -0500 Subject: [PATCH 4/5] dockers and docker_manifests formatting yaml changes, Dockerfile cURL removal and unneeded binary dir check --- .goreleaser.yaml | 94 +++++++++++++++++++++++++++++++++++++++--------- Dockerfile | 27 ++------------ 2 files changed, 80 insertions(+), 41 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index ee09c5ec..bc2967cd 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -14,6 +14,15 @@ builds: # Default: Project directory name binary: pingcli + # Custom environment variables to be set during the builds. + # Invalid environment variables will be ignored. + # For more info refer to: https://pkg.go.dev/cmd/go#hdr-Environment_variables + # + # Default: os.Environ() ++ env config section. + # Templates: allowed. + env: + - CGO_ENABLED=0 + # Custom ldflags. # # Default: '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser'. @@ -159,30 +168,81 @@ brews: token: "{{ .Env.GORELEASER_HOMEBREW_TAP_GITHUB_PAT}}" dockers: + # You can have multiple Docker images. + # Templates of the Docker image names. + # + # Templates: allowed. - image_templates: - - &amd64_image "pingidentity/pingcli:{{ .Version }}-amd64" - use: buildx - dockerfile: Dockerfile - goarch: amd64 + - "pingidentity/pingcli:{{ .Tag }}-amd64" + + # Docker build flags. + # + # Templates: allowed. build_flag_templates: - - "--platform=linux/arm64" - - "--build-arg=RELEASE_VERSION={{ .Version }}" - - image_templates: - - &arm64_image "pingidentity/pingcli:{{ .Version }}-arm64v8" + - "--platform=linux/amd64" + - "--pull" + + # GOARCH of the built binaries/packages that should be used. + # Default: 'amd64'. + goarch: amd64 + + # Set the "backend" for the Docker pipe. + # + # Valid options are: docker, buildx, podman. + # + # Podman is a GoReleaser Pro feature and is only available on Linux. + # + # Default: 'docker'. use: buildx - dockerfile: Dockerfile - goarm: "8" + + # You can have multiple Docker images. + # Templates of the Docker image names. + # + # Templates: allowed. + - image_templates: + - "pingidentity/pingcli:{{ .Tag }}-arm64" + + # Docker build flags. + # + # Templates: allowed. build_flag_templates: - "--platform=linux/arm64" - - "--build-arg=RELEASE_VERSION={{ .Version }}" + - "--pull" + + # GOARCH of the built binaries/packages that should be used. + # Default: 'amd64'. + goarch: arm64 + + # Set the "backend" for the Docker pipe. + # + # Valid options are: docker, buildx, podman. + # + # Podman is a GoReleaser Pro feature and is only available on Linux. + # + # Default: 'docker'. + use: buildx docker_manifests: - - id: pingcli + # Name for the manifest. + # + # Templates: allowed. - name_template: "pingidentity/pingcli:latest" + + # Image name to be added to this manifest. + # + # Templates: allowed. image_templates: - - *amd64_image - - *arm64_image - - name_template: "pingidentity/pingcli:{{ .Version }}" + - "pingidentity/pingcli:{{ .Tag }}-amd64" + - "pingidentity/pingcli:{{ .Tag }}-arm64" + + # Name for the manifest. + # + # Templates: allowed. + - name_template: "pingidentity/pingcli:{{ .Tag }}" + + # Image name to be added to this manifest. + # + # Templates: allowed. image_templates: - - *amd64_image - - *arm64_image + - "pingidentity/pingcli:{{ .Tag }}-amd64" + - "pingidentity/pingcli:{{ .Tag }}-arm64" diff --git a/Dockerfile b/Dockerfile index 14f32293..6b121499 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,14 @@ -# Use the official Go image as the base for building -FROM golang:1.23 as builder - -# GitHub tag -ARG RELEASE_VERSION - -# Set the working directory -WORKDIR /app - -# Download the source code from GitHub Releases -RUN curl -L https://github.com/pingidentity/pingcli/archive/refs/tags/v${RELEASE_VERSION}.tar.gz | tar xz --strip-components=1 - -# Build the pingcli binary (ensure static build) -RUN CGO_ENABLED=0 go mod tidy && CGO_ENABLED=0 go build -o /pingcli - -# Debugging step: Check if the binary exists -RUN ls -al /pingcli - # Use Alpine as the runtime image FROM alpine:latest -# Copy the binary from the builder stage -COPY --from=builder /pingcli /usr/local/bin/pingcli +# Copy in repo +COPY pingcli /usr/local/bin/ # Set permissions for the binary RUN chmod +x /usr/local/bin/pingcli -# Debugging step: Verify binary is in place -RUN ls -al /usr/local/bin/pingcli - # Set the entry point ENTRYPOINT ["pingcli"] # Allow subcommands -CMD [] +CMD [] \ No newline at end of file From c7827b8f4c46130257234ee609f61b4292d291c7 Mon Sep 17 00:00:00 2001 From: wesleymccollam Date: Fri, 10 Jan 2025 15:46:49 -0500 Subject: [PATCH 5/5] remove ldflags, add Docker usage README content --- .goreleaser.yaml | 7 ------- README.md | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index bc2967cd..522dc88d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -23,13 +23,6 @@ builds: env: - CGO_ENABLED=0 - # Custom ldflags. - # - # Default: '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser'. - # Templates: allowed. - ldflags: - - "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}" - # GOOS list to build for. # For more info refer to: https://golang.org/doc/install/source#environment # Choices for $GOOS are android, darwin, dragonfly, freebsd, illumos, ios, js, linux, netbsd, openbsd, plan9, solaris, wasip1, and windows. diff --git a/README.md b/README.md index f4efc80c..f6da997b 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,20 @@ The Ping CLI is a unified command line interface for configuring and managing Pi ## Install +#### Docker + +Use the [Ping CLI Docker image](https://hub.docker.com/r/pingidentity/pingcli) + +```text +Pull Image: +docker pull pingidentity/pingcli:latest + +Example Commands: +docker run + +docker run --version +``` + #### macOS/Linux - Homebrew Use PingIdentity's Homebrew tap to install Ping CLI