forked from tier4/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic Docker support (tier4#14)
* feat: add basic Docker support Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * ci: free disk space Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * ci: install sudo if not installed Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * chore: ignore errors for nektos/act Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * fix: add setup-qemu-action Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * ci: use self-hosted runner Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * ci: change permission of workspace for self-hosted runner Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * chore: show disk space after building docker images Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * fix: add --load to build.sh Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * feat: change WORKDIR for devel image Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * docs: update usage Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * docs: update docker/README.md Co-authored-by: Lalith Vipulananthan <63835446+LalithVipulananthan@users.noreply.github.com> Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * fix(Dockerfile): use /etc/bash.bashrc for rocker Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * docs: update docker/README.md Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * style: fix English Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * docs: apply review Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * docs: apply review Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * docs: apply review Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * ci: split ARM workflow Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * docs: apply review Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * docs: apply review Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> Co-authored-by: Lalith Vipulananthan <63835446+LalithVipulananthan@users.noreply.github.com>
- Loading branch information
1 parent
9be8901
commit c120474
Showing
11 changed files
with
519 additions
and
2 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,114 @@ | ||
name: docker-build-and-push | ||
description: "" | ||
|
||
inputs: | ||
bake-target: | ||
description: "" | ||
required: true | ||
platforms: | ||
description: "" | ||
required: true | ||
tag-suffix: | ||
description: "" | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Check branch of workflow_dispatch | ||
if: ${{ github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main' }} | ||
run: | | ||
echo "workflow_dispatch is allowed only with the branch 'refs/heads/main', '${{ github.ref }}' is not allowed." | ||
exit 1 | ||
shell: bash | ||
|
||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Install jq | ||
run: | | ||
sudo apt-get -y update | ||
sudo apt-get -y install jq | ||
shell: bash | ||
|
||
# workflow_dispatch: date | ||
# scheduled: latest, date | ||
# tag: semver | ||
- name: Set Docker tags | ||
id: set-docker-tags | ||
run: | | ||
tags=() | ||
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | ||
tags+=("{{date 'YYYYMMDD'}}") | ||
else | ||
tags+=("type=schedule,pattern=latest") | ||
tags+=("type=schedule,pattern={{date 'YYYYMMDD'}}") | ||
tags+=("type=semver,pattern={{version}}") | ||
fi | ||
# Workaround for multiline strings | ||
# https://github.community/t/set-output-truncates-multiline-strings/16852 | ||
tags_multiline=$(printf "%s\n" "${tags[@]}") | ||
tags_multiline="${tags_multiline//'%'/'%25'}" | ||
tags_multiline="${tags_multiline//$'\n'/'%0A'}" | ||
tags_multiline="${tags_multiline//$'\r'/'%0D'}" | ||
echo ::set-output name=tags::$tags_multiline | ||
shell: bash | ||
|
||
- name: Docker meta for devel | ||
id: meta-devel | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }} | ||
tags: ${{ steps.set-docker-tags.outputs.tags }} | ||
bake-target: docker-metadata-action-devel | ||
flavor: | | ||
latest=false | ||
suffix=${{ inputs.tag-suffix }} | ||
- name: Docker meta for prebuilt | ||
id: meta-prebuilt | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }} | ||
tags: ${{ steps.set-docker-tags.outputs.tags }} | ||
bake-target: docker-metadata-action-prebuilt | ||
flavor: | | ||
latest=false | ||
suffix=-prebuilt${{ inputs.tag-suffix }} | ||
- name: Login to GitHub Container Registry | ||
if: ${{ github.event_name != 'pull_request' }} | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ github.token }} | ||
|
||
# For https://github.com/docker/buildx/issues/756 | ||
- name: Merge json files | ||
run: | | ||
jq -s ".[0] * .[1]" \ | ||
"${{ steps.meta-devel.outputs.bake-file }}" \ | ||
"${{ steps.meta-prebuilt.outputs.bake-file }}" \ | ||
> bake.json | ||
shell: bash | ||
|
||
- name: Build and push | ||
uses: docker/bake-action@v1 | ||
with: | ||
push: ${{ github.event_name != 'pull_request' }} | ||
load: true | ||
files: | | ||
docker/${{ inputs.bake-target }}/docker-bake.hcl | ||
bake.json | ||
set: | | ||
*.platform=${{ inputs.platforms }} | ||
- name: Output published tags | ||
if: ${{ github.event_name != 'pull_request' }} | ||
id: output-published-tags | ||
run: | | ||
echo ::set-output name=published-tags::$(jq ".target[].tags[]" < bake.json) | ||
shell: bash |
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,36 @@ | ||
name: free-disk-space | ||
description: "" | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Install sudo | ||
run: | | ||
if ! (command -v sudo >/dev/null 2>&1); then | ||
apt-get -y update | ||
apt-get -y install sudo | ||
fi | ||
shell: bash | ||
|
||
# https://github.community/t/bug-strange-no-space-left-on-device-ioexceptions-on-github-runners/17616 | ||
- name: Free disk space | ||
run: | | ||
df -h | ||
sudo apt-get -y purge \ | ||
dotnet* \ | ||
ghc* \ | ||
php* \ | ||
|| true | ||
sudo apt-get -y autoremove | ||
sudo apt-get -y autoclean | ||
sudo rm -rf \ | ||
/usr/local/lib/android \ | ||
/usr/share/dotnet/ \ | ||
/opt/ghc | ||
docker rmi $(docker image ls -aq) || true | ||
df -h | ||
shell: bash |
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,35 @@ | ||
name: docker-build-and-push-arm | ||
|
||
on: | ||
push: | ||
tags: | ||
- v* | ||
schedule: | ||
- cron: 0 19 1,15 * * # run at 4 AM JST every two weeks | ||
workflow_dispatch: | ||
|
||
jobs: | ||
docker-build-and-push-arm: | ||
runs-on: [self-hosted, linux, ARM64] | ||
steps: | ||
# https://github.com/actions/checkout/issues/211 | ||
- name: Change permission of workspace | ||
run: | | ||
sudo chown -R $USER:$USER ${{ github.workspace }} | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Free disk space | ||
uses: ./.github/actions/free-disk-space | ||
|
||
- name: Build 'autoware-universe' | ||
uses: ./.github/actions/docker-build-and-push | ||
with: | ||
bake-target: autoware-universe | ||
platforms: linux/arm64 | ||
tag-suffix: -arm64 | ||
|
||
- name: Show disk space | ||
run: | | ||
df -h |
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,30 @@ | ||
name: docker-build-and-push | ||
|
||
on: | ||
push: | ||
tags: | ||
- v* | ||
schedule: | ||
- cron: 0 19 1,15 * * # run at 4 AM JST every two weeks | ||
workflow_dispatch: | ||
|
||
jobs: | ||
docker-build-and-push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Free disk space | ||
uses: ./.github/actions/free-disk-space | ||
|
||
- name: Build 'autoware-universe' | ||
uses: ./.github/actions/docker-build-and-push | ||
with: | ||
bake-target: autoware-universe | ||
platforms: linux/amd64 | ||
tag-suffix: -amd64 | ||
|
||
- name: Show disk space | ||
run: | | ||
df -h |
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,51 @@ | ||
name: update-docker-manifest | ||
|
||
on: | ||
schedule: | ||
- cron: 0 19 * * * # run at 4 AM JST | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update-docker-manifest: | ||
runs-on: ubuntu-latest | ||
env: | ||
PACKAGE_NAME: autoware-universe | ||
steps: | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ github.token }} | ||
|
||
- name: Create Docker manifest | ||
run: | | ||
package_full_name=ghcr.io/${{ github.repository_owner }}/${{ env.PACKAGE_NAME }} | ||
url="https://api.github.com/orgs/${{ github.repository_owner }}/packages/container/${{ matrix.package-name }}/versions" | ||
echo "url: $url" | ||
tags=$(curl -fsSL "$url" -H "Authorization: token ${{ github.token }}" | jq ".[].metadata.container.tags[]" | cut -d '"' -f 2) | ||
amd64_tags=$(echo "$tags" | grep "\-amd64" | sed "s/-amd64$//g") | ||
arm64_tags=$(echo "$tags" | grep "\-arm64" | sed "s/-arm64$//g") | ||
base_tags=$(printf "%s\n" "$amd64_tags" "$arm64_tags" | sort | uniq) | ||
echo "amd64_tags: "$amd64_tags"" | ||
echo "arm64_tags: "$arm64_tags"" | ||
echo "base_tags: "$base_tags"" | ||
for base_tag in $base_tags; do | ||
amd64_tag="$package_full_name":$(echo "$tags" | grep "$base_tag\-amd64") | ||
arm64_tag="$package_full_name":$(echo "$tags" | grep "$base_tag\-arm64") | ||
echo "base_tag: $base_tag" | ||
echo "amd64_tag: $amd64_tag" | ||
echo "arm64_tag: $arm64_tag" | ||
docker manifest create $package_full_name:$base_tag \ | ||
$amd64_tag \ | ||
$arm64_tag | ||
docker manifest push $package_full_name:$base_tag | ||
done |
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
Oops, something went wrong.