Skip to content

Commit

Permalink
Merge pull request #6 from micovery/main
Browse files Browse the repository at this point in the history
feat: update docker build for multi-arch
  • Loading branch information
micovery authored May 2, 2024
2 parents b7efd58 + ab2d724 commit 37fd642
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 9 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]

43 changes: 23 additions & 20 deletions build-docker.sh → docker-build-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 37fd642

Please sign in to comment.