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

[2.8] Release workflow #3565

Merged
merged 1 commit into from Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/build.yml
@@ -0,0 +1,65 @@
name: build

on:
push:
branches:
- 'release/*'
tags:
- 'v*'
pull_request:

env:
DOCKERHUB_SLUG: distribution/distribution

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
${{ env.DOCKERHUB_SLUG }}
### versioning strategy
### push semver tag v2.9.0 on main (default branch)
# distribution/distribution:2.9.0
# distribution/distribution:latest
### push semver tag v2.8.0 on release/2.8 branch
# distribution/distribution:2.8.0
### push on main
# distribution/distribution:edge
tags: |
type=semver,pattern={{version}}
type=ref,event=pr
# don't create latest tag on release/2.x
flavor: |
latest=false
labels: |
org.opencontainers.image.title=Distribution
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be lowercase?

Copy link
Contributor Author

@crazy-max crazy-max Jan 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took it from README: https://github.com/distribution/distribution#distribution
Other references also have capitalization: ...goals of the Distribution project?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've no strong opinions -- just wondering out loud. PR looks great! I think it's fine to leave it like this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinions either; Is this label actively used anywhere that we know of?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont believe it is -- I think it's just @crazy-max adding it from the goodness of his heart for the people who might be interested in using it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe yes that can be useful to have this kind of info ^^
Here is a sample output:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have the license, revision, etc... as labels when the image is being built.

Copy link
Contributor Author

@crazy-max crazy-max Jan 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also by default org.opencontainers.image.title and org.opencontainers.image.description will use the one from the GitHub API if we remove these override. In our case would result with:

  • org.opencontainers.image.title: "distribution" (repo name)
  • org.opencontainers.image.description: "The toolkit to pack, ship, store, and deliver container content" (repo description)

So we can remove them in the workflow if the default ones suit to you

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kewl. There is no harm keeping them in. Thanks @crazy-max

org.opencontainers.image.description=The toolkit to pack, ship, store, and deliver container content
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build image
uses: docker/bake-action@v1
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: image-all
push: ${{ startsWith(github.ref, 'refs/tags/') }}
45 changes: 31 additions & 14 deletions Dockerfile
@@ -1,23 +1,40 @@
FROM golang:1.16-alpine AS build
# syntax=docker/dockerfile:1.3

ENV GO111MODULE=auto
ENV DISTRIBUTION_DIR /go/src/github.com/docker/distribution
ENV BUILDTAGS include_oss include_gcs
ARG GO_VERSION=1.16
ARG GORELEASER_XX_VERSION=1.2.5

ARG GOOS=linux
ARG GOARCH=amd64
ARG GOARM=6
FROM --platform=$BUILDPLATFORM crazymax/goreleaser-xx:${GORELEASER_XX_VERSION} AS goreleaser-xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
COPY --from=goreleaser-xx / /
RUN apk add --no-cache file git
WORKDIR /go/src/github.com/docker/distribution

RUN set -ex \
&& apk add --no-cache make git file
FROM base AS build
ENV GO111MODULE=auto
ENV CGO_ENABLED=0
ARG TARGETPLATFORM
ARG PKG="github.com/distribution/distribution"
ARG BUILDTAGS="include_oss include_gcs"
RUN --mount=type=bind,rw \
--mount=type=cache,target=/root/.cache/go-build \
--mount=target=/go/pkg/mod,type=cache \
goreleaser-xx --debug \
--name="registry" \
--dist="/out" \
--main="./cmd/registry" \
--flags="-v" \
--ldflags="-s -w -X '$PKG/version.Version={{.Version}}' -X '$PKG/version.Revision={{.Commit}}' -X '$PKG/version.Package=$PKG'" \
--tags="$BUILDTAGS" \
--files="LICENSE" \
--files="README.md"

WORKDIR $DISTRIBUTION_DIR
COPY . $DISTRIBUTION_DIR
RUN CGO_ENABLED=0 make PREFIX=/go clean binaries && file ./bin/registry | grep "statically linked"
FROM scratch AS binary
COPY --from=build /usr/local/bin/registry* /

FROM alpine
FROM alpine:3.14
RUN apk add --no-cache ca-certificates
COPY cmd/registry/config-dev.yml /etc/docker/registry/config.yml
COPY --from=build /go/src/github.com/docker/distribution/bin/registry /bin/registry
COPY --from=build /usr/local/bin/registry /bin/registry
VOLUME ["/var/lib/registry"]
EXPOSE 5000
ENTRYPOINT ["registry"]
Expand Down
34 changes: 34 additions & 0 deletions docker-bake.hcl
@@ -0,0 +1,34 @@
group "default" {
targets = ["image-local"]
}

// Special target: https://github.com/docker/metadata-action#bake-definition
target "docker-metadata-action" {
tags = ["registry:local"]
}

target "binary" {
target = "binary"
output = ["./bin"]
}

target "image" {
inherits = ["docker-metadata-action"]
}

target "image-local" {
inherits = ["image"]
output = ["type=docker"]
}

target "image-all" {
inherits = ["image"]
platforms = [
"linux/amd64",
"linux/arm/v6",
"linux/arm/v7",
"linux/arm64",
"linux/ppc64le",
"linux/s390x"
]
}