Skip to content

Commit

Permalink
fix(docker): use native shell way of docker buildx
Browse files Browse the repository at this point in the history
  • Loading branch information
dalisoft committed Apr 28, 2024
1 parent 437b91c commit 3a69068
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions plugins/docker.sh
Original file line number Diff line number Diff line change
@@ -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!"

Expand All @@ -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
Expand Down

0 comments on commit 3a69068

Please sign in to comment.