diff --git a/.github/workflows/publish-docker-image.yaml b/.github/workflows/publish-docker-image.yaml index 330dc42..7eb914f 100644 --- a/.github/workflows/publish-docker-image.yaml +++ b/.github/workflows/publish-docker-image.yaml @@ -18,4 +18,4 @@ jobs: - name: docker build and push env: GIT_REPO: ${{ github.repository }} - run: ./build-docker.sh push + run: ./docker-build-push.sh diff --git a/Dockerfile b/Dockerfile index 3a807d8..683d27f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,36 +14,21 @@ # limitations under the License. # -FROM golang:1.21 as builder - -ARG GIT_REPO -ARG GIT_TAG -ARG GIT_COMMIT -ARG BUILD_TIMESTAMP +FROM --platform=$BUILDPLATFORM golang:alpine as builder +RUN apk update && apk add --no-cache git ADD ./ /src WORKDIR /src -RUN ./build.sh -FROM golang:1.21 +ARG TARGETOS +ARG TARGETARCH +ENV GOOS=$TARGETOS +ENV GOARCH=$TARGETARCH -COPY LICENSE / +RUN sh build.sh +FROM --platform=$TARGETPLATFORM alpine:3 +COPY LICENSE / COPY --from=builder /src/bin/* /usr/local/bin/ - -ARG GIT_REPO -ARG GIT_TAG -ARG GIT_COMMIT -ARG BUILD_TIMESTAMP - -LABEL org.opencontainers.image.url="https://github.com/${GIT_REPO}" \ - org.opencontainers.image.documentation="https://github.com/${GIT_REPO}" \ - org.opencontainers.image.source="https://github.com/${GIT_REPO}" \ - org.opencontainers.image.version="${GIT_TAG}" \ - org.opencontainers.image.revision="${GIT_COMMIT}" \ - org.opencontainers.image.vendor='Google LLC' \ - org.opencontainers.image.licenses='Apache-2.0' \ - org.opencontainers.image.description='This is a tool for generating Apigee bundles and shared flows' - ENTRYPOINT [ "apigee-go-gen" ] diff --git a/build-docker.sh b/docker-build-push.sh similarity index 60% rename from build-docker.sh rename to docker-build-push.sh index cab011d..dd967ea 100755 --- a/build-docker.sh +++ b/docker-build-push.sh @@ -31,7 +31,9 @@ sortSemver() { pickLatestRelease() { local first="" while read version; do - first="${version}" + if [[ -z "${first}" ]] ; then + first="${version}" + fi if [[ "${version}" != *"-"* ]] ; then echo "${version}" return @@ -48,37 +50,38 @@ getLatestRelease() { echo "$(getReleasedTags | sortSemver | pickLatestRelease)" } - REGISTRY="${REGISTRY:-ghcr.io}" GIT_REPO="${GIT_REPO:-apigee/apigee-go-gen}" -BUILD_TIMESTAMP=$(date "+%s") GIT_COMMIT=$(git rev-parse --short HEAD) GIT_TAG=$(git describe --tags --abbrev=0) -LATEST_TAG="$(getLatestRelease)" -if [[ "${LATEST_TAG}" == "${GIT_TAG}" ]] ; then +if [[ "$(getLatestRelease)" == "${GIT_TAG}" ]] ; then BUILD_TAG="latest" else BUILD_TAG="${GIT_TAG}" fi - -echo "LATEST_TAG=${LATEST_TAG}" echo "BUILD_TAG=${BUILD_TAG}" echo "GIT_TAG=${GIT_TAG}" -echo "GIT_COMMIT=${GIT_COMMIT}" -docker build -t "${REGISTRY}/${GIT_REPO}:${BUILD_TAG}" \ - -t "${REGISTRY}/${GIT_REPO}:${GIT_TAG}" \ - -t "${REGISTRY}/${GIT_REPO}:${GIT_COMMIT}" \ - --build-arg "GIT_REPO=${GIT_REPO}" \ - --build-arg="GIT_TAG=${GIT_TAG}" \ - --build-arg="GIT_COMMIT=${GIT_COMMIT}" \ - --build-arg="BUILD_TIMESTAMP=${BUILD_TIMESTAMP}" \ +docker buildx create --name builder --use + +OCI="index:org.opencontainers.image" +docker buildx build \ + --platform=linux/amd64,linux/arm64 \ + --tag "${REGISTRY}/${GIT_REPO}:${GIT_TAG}" \ + --tag "${REGISTRY}/${GIT_REPO}:${BUILD_TAG}" \ + --provenance false \ + --output type=registry \ + --annotation "${OCI}.url=https://github.com/${GIT_REPO}" \ + --annotation "${OCI}.documentation=https://github.com/${GIT_REPO}" \ + --annotation "${OCI}.source=https://github.com/${GIT_REPO}" \ + --annotation "${OCI}.version=${GIT_TAG}" \ + --annotation "${OCI}.revision=${GIT_COMMIT}" \ + --annotation "${OCI}.vendor=Google LLC" \ + --annotation "${OCI}.licenses=Apache-2.0" \ + --annotation "${OCI}.description=This is a tool for generating Apigee bundles and shared flows" \ + --push \ . -if [ "${1}" == "push" ] ; then - docker push "${REGISTRY}/${GIT_REPO}:${BUILD_TAG}" - docker push "${REGISTRY}/${GIT_REPO}:${GIT_TAG}" - docker push "${REGISTRY}/${GIT_REPO}:${GIT_COMMIT}" -fi +docker buildx rm builder