diff --git a/plugins/docker.sh b/plugins/docker.sh index aa1d582..0fd2b7c 100644 --- a/plugins/docker.sh +++ b/plugins/docker.sh @@ -1,9 +1,33 @@ #!/bin/sh set -eu +# Docker buildx script was copied from +# https://docs.docker.com/build/cloud/ci +# and modified by @dalisoft for AMD64/ARM64 platforms +BUILDX_URL= +ARCH=$(uname -m | sed 's/aarch64/arm64/' | sed 's/x86_64/amd64/') + +prepare() { + BUILDX_URL=$(curl -s https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/buildx-lab-releases.json | jq -r ".latest.assets[] | select(endswith(\"linux-${ARCH}\"))") + + # Download docker buildx with Hyrdobuild support + mkdir -vp ~/.docker/cli-plugins/ + curl --silent -L --output ~/.docker/cli-plugins/docker-buildx "${BUILDX_URL}" + chmod a+x ~/.docker/cli-plugins/docker-buildx + + echo "${DOCKER_HUB_PAT-}" | docker login --username "${DOCKER_HUB_USERNAME-}" --password-stdin +} + +cleanup() { + rm -rf ~/.docker/cli-plugins/ + + docker logout +} + release() { # Build and publish a `Docker` tag - if [ -n "${DOCKER_HUB_PAT-}" ]; then + if [ -n "${DOCKER_HUB_USERNAME-}" ] && [ -n "${DOCKER_HUB_PAT-}" ]; then + log "Building and publishing Docker image..." log_verbose "Docker tag: $NEXT_RELEASE_TAG and version: $NEXT_RELEASE_VERSION!" @@ -16,14 +40,21 @@ release() { return 1 fi - docker build . -t "$GIT_REPO_NAME:$NEXT_BUILD_VERSION" + prepare + + docker buildx use "${DOCKER_BUILDX_NAME-}" + docker buildx inspect --bootstrap + docker buildx build --platform=linux/amd64,linux/arm64 -t "$GIT_REPO_NAME:$NEXT_BUILD_VERSION" . --push docker tag "$GIT_REPO_NAME:$NEXT_BUILD_VERSION" "$GIT_REPO_NAME:latest" docker push "$GIT_REPO_NAME" log "Docker image published [$NEXT_RELEASE_TAG]!" + + cleanup else log "Skipped Docker image [$NEXT_RELEASE_TAG] in DRY-RUN mode." fi + else echo " Docker Personal Access Token is not found