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

add different platforms for docker img #417

Merged
merged 2 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
with:
fetch-depth: 0
- run: echo ${{ secrets.DOCKER_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- run: tools/docker.sh
- run: tools/docker.sh "linux/amd64,linux/arm64"

Choose a reason for hiding this comment

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

Also, check if the list of parameters is empty. if it is, go with the regular build.

38 changes: 34 additions & 4 deletions tools/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,37 @@

set -e

for tag in latest $(git tag --points-at | sed s/^v//); do
docker build -t raviqqe/muffet:$tag .
docker push raviqqe/muffet:$tag
done
check_buildx(){
if docker buildx version &>/dev/null; then
return 0
fi
if docker buildx ls &>/dev/null; then
return 0
fi
return 1
}

Choose a reason for hiding this comment

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

When it comes to make sure if buildx is installed I'd recommend you this:

Suggested change
check_buildx(){
if docker buildx version &>/dev/null; then
return 0
fi
if docker buildx ls &>/dev/null; then
return 0
fi
return 1
}
check_buildx(){
docker buildx &>/dev/null
return @?
}


build_multiarch() {
if ! check_buildx; then

Choose a reason for hiding this comment

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

Suggested change
if ! check_buildx; then
if check_buildx; then
echo "Building for platforms: $platforms"
# Build for each git tag and latest
for tag in latest $(git tag --points-at | sed s/^v//); do
docker buildx build \
--platform "$platforms" \
--tag raviqqe/muffet:$tag \
--push \
.
done
else
for tag in latest $(git tag --points-at | sed s/^v//); do
docker build -t raviqqe/muffet:$tag .
docker push raviqqe/muffet:$tag
done
fi

echo "Error: Docker buildx is not installed or not working"
return 1
fi

local platforms=${1:-"linux/amd64"}

docker buildx create --name multiarch --use || true

echo "Building for platforms: $platforms"

# Build for each git tag and latest
for tag in latest $(git tag --points-at | sed s/^v//); do
docker buildx build \
--platform "$platforms" \
--tag raviqqe/muffet:$tag \
--push \
.
done
}


build_multiarch "$@"
Copy link

@danvergara danvergara Nov 3, 2024

Choose a reason for hiding this comment

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

Not sure if building the image for multiple architectures as the only option is the best solution.

Why don't you add the regular build as the default behavior in case the user doesn't have buildx installed or they don't pass any platform as a parameter?

Suggested change
build_multiarch "$@"
build_image "$@"