-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from CMU-cabot/ros2-dev-bake
build docker images by buildx bake
- Loading branch information
Showing
50 changed files
with
2,020 additions
and
1,362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Test Building Docker Image and Workspace | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
target: | ||
required: false | ||
default: "" | ||
type: string | ||
secrets: | ||
dockerhub-token: | ||
required: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Maximize build space | ||
run: | | ||
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android | ||
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET | ||
sudo rm -rf /opt/ghc | ||
echo "Available storage:" | ||
df -h | ||
docker system prune -a --volumes -f # delete unnecessary preinstalled docker images | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Install vcs | ||
run: pip3 install vcstool | ||
|
||
- name: Prepare thirdparty repos | ||
run: ./setup-dependency.sh | ||
|
||
- name: Buildx bake | ||
shell: bash | ||
run: | | ||
docker login -u daisukesato80 -p "${{ secrets.dockerhub-token }}" | ||
./bake-docker.sh ${{ inputs.target }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Build Docker Image | ||
|
||
on: | ||
push: | ||
branches: [ ros2, ros2-dev-bake ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Build docker image | ||
run: | | ||
curl -X POST \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: token ${{ secrets.CABOT_BUILD_TOKEN}}" \ | ||
https://api.github.com/repos/CMU-cabot/cabot-build/dispatches \ | ||
-d '{"event_type": "build-push", "client_payload":{"repository": "${{ github.repository }}", "ref_name": "${{ github.ref_name }}"}}' | ||
env: | ||
PAT: ${{ secrets.CABOT_BUILD_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright (c) 2024 Carnegie Mellon University | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
|
||
# This script overview: | ||
# - Builds the necessary images for cabot on multiple platforms and pushes them to cmucal. | ||
# - Since push requires cmucal permissions, it is usually handled by an Action script. | ||
# - If you want to debug by modifying the base image, perform a local build (-l). | ||
# - Set up a local registry server, build, and overwrite the cmucal image tag. | ||
# - It is also advisable to specify the platform (-p) in this case. | ||
|
||
function help { | ||
echo "Usage: $0 [-i] [-l] [-b <base_name>] [-P <platform>]" | ||
echo "" | ||
echo "-h show this help" | ||
echo "-b <base_name> bake with base_name" | ||
echo "-i image build for debug - shorthand for -l and -P with host platform" | ||
echo "-l build using local registry" | ||
echo "-P <platform> specify platform" | ||
echo " build linux/arm64 and linux/amd64 if not specified" | ||
echo "-t <tags> additional tags" | ||
} | ||
|
||
platform= | ||
base_name=cabot-base | ||
service=bag | ||
local=0 | ||
tags= | ||
|
||
while getopts "hb:ilP:t:" arg; do | ||
case $arg in | ||
h) | ||
help | ||
exit | ||
;; | ||
b) | ||
base_name=${OPTARG} | ||
;; | ||
i) | ||
if [[ $(uname -m) = "x86_64" ]]; then | ||
platform="linux/amd64" | ||
elif [[ $(uname -m) = "aarch64" ]]; then | ||
platform="linux/arm64" | ||
fi | ||
local=1 | ||
;; | ||
l) | ||
local=1 | ||
;; | ||
P) | ||
platform=${OPTARG} | ||
;; | ||
t) | ||
tags=${OPTARG} | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND-1)) | ||
|
||
if [[ -z $base_name ]]; then | ||
help | ||
exit 1 | ||
fi | ||
|
||
if [[ -z $(docker network ls | grep "registry-network") ]]; then | ||
docker network create registry-network | ||
fi | ||
if [[ $local -eq 1 ]]; then | ||
export REGISTRY=registry:5000 | ||
# setup local docker registry for multiplatform support | ||
if [[ -z $(docker ps -f "name=registry" -q) ]]; then | ||
docker run -d \ | ||
--rm \ | ||
--name registry \ | ||
--network registry-network \ | ||
-p 127.0.0.1:9092:5000 \ | ||
registry:2.7 | ||
fi | ||
else | ||
export REGISTRY=cmucal | ||
fi | ||
|
||
# setup multiplatform builder | ||
# docker buildx rm mybuilder | ||
if [[ -z $(docker buildx ls | grep "mybuilder\*") ]]; then | ||
echo "mybuilder is not selected" | ||
if [[ -z $(docker buildx ls | grep mybuilder) ]]; then | ||
echo "creating mybuilder" | ||
docker buildx create --use --name mybuilder --driver docker-container \ | ||
--config buildkitd.toml \ | ||
--driver-opt network=registry-network # option to make the builder access to the registry on the localhost | ||
else | ||
echo "use mybuilder" | ||
docker buildx use mybuilder | ||
fi | ||
fi | ||
|
||
# tag option | ||
tag_option= | ||
if [[ -z $tags ]]; then | ||
tags="latest,$(git rev-parse --abbrev-ref HEAD)" | ||
fi | ||
tag_option="--set=${service}.tags=${REGISTRY}/cabot-${service}:{${tags}}" | ||
|
||
# platform option | ||
platform_option= | ||
if [[ -n $platform ]]; then | ||
platform_option="--set=*.platform=\"$platform\"" | ||
fi | ||
|
||
# bake | ||
com="docker buildx bake -f docker-compose.yaml $platform_option $tag_option $service" | ||
export BASE_IMAGE=$base_name | ||
echo $com | ||
eval $com | ||
if [[ $? -ne 0 ]]; then | ||
echo "failed to build image" | ||
exit 1 | ||
fi | ||
|
||
# reset buildx builder to default | ||
docker buildx use default | ||
|
||
# copy images from local registry | ||
# this can override image tag | ||
if [[ $local -eq 1 ]]; then | ||
tags=($(eval "$com --print" 2> /dev/null | jq -r '.target[].tags[] | split("/")[-1]' | jq --raw-input | jq -r --slurp 'join(" ")')) | ||
for tag in "${tags[@]}"; do | ||
echo "Pulling tag ($tag) from $REGISTRY (platform=$(uname -m))" | ||
com="docker pull localhost:9092/$tag" | ||
echo $com | ||
eval $com | ||
com="docker image tag localhost:9092/$tag cmucal/$tag" | ||
echo $com | ||
eval $com | ||
done | ||
fi |
Oops, something went wrong.