Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gh actions for building container images on release #2000

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/release-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: container-build

on:
push:
tags: ['*']

env:
KO_DEFAULTPLATFORMS: all

jobs:
release-container:
name: Build the release container images
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
- id: lowercase-repository-name
uses: ASzc/change-string-case-action@v6
with:
string: ${{ github.repository }}
- name: Get tag name
id: tag_name
run: |
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.21
check-latest: true
- name: Setup Ko
uses: ko-build/[email protected]
- name: Build the crane-ish builder images
run: |
ko build -B github.com/google/go-containerregistry/cmd/crane -t latest -t $GITHUB_SHA -t $SOURCE_TAG
ko build -B github.com/google/go-containerregistry/cmd/gcrane -t latest -t $GITHUB_SHA -t $SOURCE_TAG
# ./cmd/krane is a separate module, so switch directories.
cd ./cmd/krane
ko build -B github.com/google/go-containerregistry/cmd/krane -t latest -t $GITHUB_SHA -t $SOURCE_TAG
env:
KO_DOCKER_REPO: ghcr.io/${{ steps.lowercase-repository-name.outputs.lowercase }}
SOURCE_TAG: ${{ steps.tag_name.outputs.SOURCE_TAG }}
KO_CONFIG_PATH: ${{ github.workspace }}/.ko/default/.ko.yaml
- name: Build the crane-ish builder debug images
run: |
ko build -B github.com/google/go-containerregistry/cmd/crane -t "debug"
ko build -B github.com/google/go-containerregistry/cmd/gcrane -t "debug"
# ./cmd/krane is a separate module, so switch directories.
cd ${{ github.workspace }}/cmd/krane
ko build -B github.com/google/go-containerregistry/cmd/krane -t "debug"
env:
KO_CONFIG_PATH: ${{ github.workspace }}/.ko/debug/.ko.yaml
- name: Build the tag specific debug images
run: |
KO_DOCKER_REPO=ghcr.io/${{ steps.lowercase-repository-name.outputs.lowercase }}/crane/debug ko build --bare github.com/google/go-containerregistry/cmd/crane -t latest -t $GITHUB_SHA -t $SOURCE_TAG
KO_DOCKER_REPO=ghcr.io/${{ steps.lowercase-repository-name.outputs.lowercase }}/gcrane/debug ko build --bare github.com/google/go-containerregistry/cmd/gcrane -t latest -t $GITHUB_SHA -t $SOURCE_TAG
# ./cmd/krane is a separate module, so switch directories.
cd ./cmd/krane
KO_DOCKER_REPO=ghcr.io/${{ steps.lowercase-repository-name.outputs.lowercase }}/krane/debug ko build --bare github.com/google/go-containerregistry/cmd/krane -t latest -t $GITHUB_SHA -t $SOURCE_TAG
env:
KO_CONFIG_PATH: ${{ github.workspace }}/.ko/debug/.ko.yaml
SOURCE_TAG: ${{ steps.tag_name.outputs.SOURCE_TAG }}
8 changes: 4 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ release:
footer: |
### Container Images
https://gcr.io/go-containerregistry/crane:{{.Tag}}
https://gcr.io/go-containerregistry/gcrane:{{.Tag}}
https://ghcr.io/google/go-containerregistry/crane:{{.Tag}}
https://ghcr.io/google/go-containerregistry/gcrane:{{.Tag}}
For example:
```
docker pull gcr.io/go-containerregistry/crane:{{.Tag}}
docker pull gcr.io/go-containerregistry/gcrane:{{.Tag}}
docker pull ghcr.io/google/go-containerregistry/crane:{{.Tag}}
docker pull ghcr.io/google/go-containerregistry/gcrane:{{.Tag}}
```
5 changes: 5 additions & 0 deletions .ko/debug/.ko.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
defaultBaseImage: gcr.io/distroless/base:debug
defaultFlags:
- -trimpath
defaultLdflags:
- -X github.com/google/go-containerregistry/cmd/crane/cmd.Version={{.Git.Tag}}
- -X github.com/google/go-containerregistry/pkg/v1/remote/transport.Version={{.Git.Tag}}
5 changes: 5 additions & 0 deletions .ko/default/.ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defaultFlags:
- -trimpath
defaultLdflags:
- -X github.com/google/go-containerregistry/cmd/crane/cmd.Version={{.Git.Tag}}
- -X github.com/google/go-containerregistry/pkg/v1/remote/transport.Version={{.Git.Tag}}
16 changes: 11 additions & 5 deletions cmd/crane/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ steps:

## Images

You can also use crane as docker image
You can also use crane as docker image. Newer releases are published in the GitHub container registry:

```sh
$ docker run --rm gcr.io/go-containerregistry/crane ls ubuntu
docker run --rm ghcr.io/google/go-containerregistry/crane ls ubuntu
10.04
12.04.5
12.04
Expand All @@ -99,10 +99,16 @@ $ docker run --rm gcr.io/go-containerregistry/crane ls ubuntu
And it's also available with a shell, at the `:debug` tag:

```sh
docker run --rm -it --entrypoint "/busybox/sh" gcr.io/go-containerregistry/crane:debug
docker run --rm -it --entrypoint "/busybox/sh" ghcr.io/google/go-containerregistry/crane:debug
```

Tagged debug images are available at `gcr.io/go-containerregistry/crane/debug:[tag]`.
Tagged debug images are available at `ghcr.io/google/go-containerregistry/crane/debug:[tag]`.

Note that some older releases are only available in the google container registry, respectively at:

- `gcr.io/go-containerregistry/crane`
- `gcr.io/go-containerregistry/crane:debug`
- `gcr.io/go-containerregistry/crane/debug:[tag]`

### Using with GitLab

Expand All @@ -114,7 +120,7 @@ docker-tag-latest:
refs:
- main
image:
name: gcr.io/go-containerregistry/crane:debug
name: ghcr.io/google/go-containerregistry/crane:debug
entrypoint: [""]
script:
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
Expand Down
6 changes: 3 additions & 3 deletions cmd/gcrane/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ gcrane gc gcr.io/${PROJECT_ID}/repo | xargs -n1 gcrane delete
You can also use gcrane as docker image

```sh
$ docker run --rm gcr.io/go-containerregistry/gcrane ls gcr.io/google-containers/busybox
$ docker run --rm ghcr.io/google/go-containerregistry/gcrane ls gcr.io/google-containers/busybox
gcr.io/google-containers/busybox@sha256:4bdd623e848417d96127e16037743f0cd8b528c026e9175e22a84f639eca58ff
gcr.io/google-containers/busybox:1.24
gcr.io/google-containers/busybox@sha256:545e6a6310a27636260920bc07b994a299b6708a1b26910cfefd335fdfb60d2b
Expand All @@ -59,7 +59,7 @@ gcr.io/google-containers/busybox:latest
And it's also available with a shell, at the `:debug` tag:

```sh
docker run --rm -it --entrypoint "/busybox/sh" gcr.io/go-containerregistry/gcrane:debug
docker run --rm -it --entrypoint "/busybox/sh" ghcr.io/google/go-containerregistry/gcrane:debug
```

Tagged debug images are available at `gcr.io/go-containerregistry/gcrane/debug:[tag]`.
Tagged debug images are available at `ghcr.io/google/go-containerregistry/gcrane/debug:[tag]`.
Loading