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

feat(docker): re-organize the autoware docker containers #4072

Merged
merged 17 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions .devcontainer/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ghcr.io/autowarefoundation/autoware-openadk:latest-devel

ENV SHELL /bin/bash

ARG USERNAME=autoware
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
24 changes: 24 additions & 0 deletions .devcontainer/base/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "Autoware",
"build": {
"dockerfile": "Dockerfile"
},
"remoteUser": "autoware",
"hostRequirements": {
"gpu": true
},
Comment on lines +7 to +9
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed for this non-GPU file. Although it is not critical because if I remember correctly it just issues a warning in the logs, but doesn't block anything.

Copy link
Collaborator

Choose a reason for hiding this comment

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

resolving following #4072 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not good at VSCode with Containers, I don't know if this affects anything related to RViz. If you think we can remove it safely, I can remove it.

Copy link
Collaborator

@ambroise-arm ambroise-arm Mar 6, 2024

Choose a reason for hiding this comment

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

It won't change how things get setup. From https://containers.dev/implementors/json_reference/#min-host-reqs: "you will be presented with a warning if the requirements are not met". Removing this won't affect whether rviz works or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ambroise-arm I see, I will let @oguzkaganozt know this, let's remove it as well in the next PR.

"runArgs": [
"--cap-add=SYS_PTRACE",

Check warning on line 11 in .devcontainer/base/devcontainer.json

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (PTRACE)
"--security-opt",
"seccomp=unconfined",

Check warning on line 13 in .devcontainer/base/devcontainer.json

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (seccomp)
"--net=host",
"--volume=/etc/localtime:/etc/localtime:ro"

Check warning on line 15 in .devcontainer/base/devcontainer.json

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (localtime)

Check warning on line 15 in .devcontainer/base/devcontainer.json

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (localtime)
],
"customizations": {
"vscode": {
"settings.json": {
"terminal.integrated.profiles.linux": { "bash": { "path": "/bin/bash" } }
}
}
}
}
14 changes: 14 additions & 0 deletions .devcontainer/cuda/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ghcr.io/autowarefoundation/autoware-openadk:latest-devel-cuda
Copy link
Collaborator

Choose a reason for hiding this comment

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

If apart from this line the rest of the file is exactly the same as in base/Dockerfile then I think it would be better to keep a single Dockerfile under .devcontainer/ and instead have an ARG TAG or something like that in order to use FROM ghcr.io/autowarefoundation/autoware-openadk:$TAG and then pass it with build.args (https://containers.dev/implementors/json_reference/#image-specific) in the respective devcontainer.json

Copy link
Contributor

@xmfcx xmfcx Mar 6, 2024

Choose a reason for hiding this comment

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

@oguzkaganozt will look into this tomorrow in a follow up PR.

Let's merge this as it is today.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok


ENV SHELL /bin/bash

ARG USERNAME=autoware
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
26 changes: 26 additions & 0 deletions .devcontainer/cuda/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "Autoware-cuda",
"build": {
"dockerfile": "Dockerfile"
},
"remoteUser": "autoware",
"hostRequirements": {
"gpu": true
},
"runArgs": [
"--cap-add=SYS_PTRACE",

Check warning on line 11 in .devcontainer/cuda/devcontainer.json

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (PTRACE)
"--security-opt",
"seccomp=unconfined",

Check warning on line 13 in .devcontainer/cuda/devcontainer.json

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (seccomp)
"--net=host",
"--volume=/etc/localtime:/etc/localtime:ro",

Check warning on line 15 in .devcontainer/cuda/devcontainer.json

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (localtime)

Check warning on line 15 in .devcontainer/cuda/devcontainer.json

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (localtime)
"--gpus",
"all"
],
"customizations": {
"vscode": {
"settings.json": {
"terminal.integrated.profiles.linux": { "bash": { "path": "/bin/bash" } }
}
}
}
}
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ignore git and metadata directories
.git
.github
.vscode

# Ignore all markdown files
*.md

# Ignore Docker files
docker-bake.hcl

# Etc
*.ignore
*.lint
*.lock
*.log
*.out
49 changes: 0 additions & 49 deletions .github/actions/create-main-distro-alias/action.yaml

This file was deleted.

127 changes: 105 additions & 22 deletions .github/actions/docker-build-and-push/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,36 @@ runs:
sudo apt-get -y install jq
shell: bash

# workflow_dispatch: latest, date
# schedule: latest, date
# tag: semver
- name: Set Docker tags
id: set-docker-tags
run: |
tags=()
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
tags+=("latest")
tags+=("{{date 'YYYYMMDD'}}")
else
tags+=("type=schedule,pattern=latest")
tags+=("type=schedule,pattern={{date 'YYYYMMDD'}}")
tags+=("type=semver,pattern={{version}}")
tags+=("type=match,pattern=\d+.\d+")
if [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref_type }}" == "tag" ]; then
tags+=("$(echo "${{ github.ref }}" | sed -E 's/.*([vV][0-9]+\.[0-9]+\.[0-9]+).*/\1/')")
fi

tags+=("{{date 'YYYYMMDD'}}")
tags+=("latest")
tags+=("latest-${{ inputs.tag-prefix }}")

# Output multiline strings: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "tags<<$EOF" >> $GITHUB_OUTPUT
echo "$(printf "%s\n" "${tags[@]}")" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
shell: bash

- name: Docker meta for prebuilt
id: meta-prebuilt
uses: docker/metadata-action@v4
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: Docker meta for devel
id: meta-devel
uses: docker/metadata-action@v4
Expand All @@ -64,20 +70,19 @@ runs:
bake-target: docker-metadata-action-devel
flavor: |
latest=false
prefix=${{ inputs.tag-prefix }}
suffix=${{ inputs.tag-suffix }}
suffix=-devel${{ inputs.tag-suffix }}

- name: Docker meta for prebuilt
id: meta-prebuilt
- name: Docker meta for runtime
if: ${{ github.event_name == 'workflow_dispatch' }} || ${{ (github.event_name == 'push' && github.ref_type == 'tag') }}
id: meta-runtime
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }}
tags: ${{ steps.set-docker-tags.outputs.tags }}
bake-target: docker-metadata-action-prebuilt
bake-target: docker-metadata-action-runtime
flavor: |
latest=false
prefix=${{ inputs.tag-prefix }}
suffix=-prebuilt${{ inputs.tag-suffix }}
latest=${{ github.event_name == 'push' && github.ref_type == 'tag' }}
suffix=-runtime${{ inputs.tag-suffix }}

- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' }}
Expand All @@ -87,15 +92,93 @@ runs:
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and push
- name: Build and Push - prebuilt and devel
if: ${{ (github.event_name == 'push' && github.ref_type == 'branch') || github.event_name == 'schedule' }}
uses: docker/bake-action@v3
with:
push: ${{ inputs.allow-push == 'true' }}
files: |
docker/${{ inputs.bake-target }}/docker-bake.hcl
${{ steps.meta-prebuilt.outputs.bake-file }}
${{ steps.meta-devel.outputs.bake-file }}
targets: |
prebuilt
devel
provenance: false
set: |
${{ inputs.build-args }}

- name: Build and Publish to GitHub Container Registry
if: ${{ ( github.event_name == 'push' && github.ref_type == 'tag' ) || ( github.event_name == 'workflow_dispatch' && github.event.inputs.artifacts-destination == 'registry') }}
uses: docker/bake-action@v3
with:
# Checking event_name for https://github.com/autowarefoundation/autoware/issues/2796
push: ${{ (github.event_name == 'schedule' || github.ref_name == github.event.repository.default_branch || github.event_name == 'push') && inputs.allow-push == 'true' }}
push: true
files: |
docker/${{ inputs.bake-target }}/docker-bake.hcl
${{ steps.meta-devel.outputs.bake-file }}
${{ steps.meta-prebuilt.outputs.bake-file }}
${{ steps.meta-runtime.outputs.bake-file }}
provenance: false
set: |
${{ inputs.build-args }}

- name: Build and Save Artifacts
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.artifacts-destination == 'tarball' }}
uses: docker/bake-action@v3
with:
push: false
files: |
docker/${{ inputs.bake-target }}/docker-bake.hcl
${{ steps.meta-devel.outputs.bake-file }}
${{ steps.meta-prebuilt.outputs.bake-file }}
${{ steps.meta-runtime.outputs.bake-file }}
provenance: false
set: |
${{ inputs.build-args }}
prebuilt.output=type=docker,dest=/tmp/prebuilt.tar
devel.output=type=docker,dest=/tmp/devel.tar
runtime.output=type=docker,dest=/tmp/runtime.tar

- name: Upload Artifact - prebuilt
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.artifacts-destination == 'tarball' }}
id: artifact-upload-step-prebuilt
uses: actions/upload-artifact@v4
with:
name: prebuilt-image${{ inputs.tag-suffix }}
path: /tmp/prebuilt.tar
retention-days: 7
compression-level: 6
overwrite: true
if-no-files-found: error

- name: Upload Artifact - devel
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.artifacts-destination == 'tarball' }}
id: artifact-upload-step-devel
uses: actions/upload-artifact@v4
with:
name: devel-image${{ inputs.tag-suffix }}
path: /tmp/devel.tar
retention-days: 7
compression-level: 6
overwrite: true
if-no-files-found: error

- name: Upload Artifact - runtime
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.artifacts-destination == 'tarball' }}
id: artifact-upload-step-runtime
uses: actions/upload-artifact@v4
with:
name: runtime-image${{ inputs.tag-suffix }}
path: /tmp/runtime.tar
retention-days: 7
compression-level: 6
overwrite: true
if-no-files-found: error

- name: Output artifact URLs
id: output-artifact-urls
run: |
echo 'prebuilt URL ${{ steps.artifact-upload-step-prebuilt.outputs.artifact-url }}'
echo 'devel URL ${{ steps.artifact-upload-step-devel.outputs.artifact-url }}'
echo 'runtime URL ${{ steps.artifact-upload-step-runtime.outputs.artifact-url }}'
shell: bash
33 changes: 25 additions & 8 deletions .github/workflows/docker-build-and-push-main-self-hosted.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
# EVENTS: push, schedule, workflow_dispatch
# workflow_dispatch: Build all. No publish to registry; save as tarball.
# schedule: Build only devel and prebuilt. TAGS: date, latest
# push-branch: Build only devel and prebuilt. TAGS: date, latest
# push-tag: Build all. TAGS: version, date, latest

name: docker-build-and-push-main-self-hosted

on:
push:
tags:
- v*
- "[0-9]+.[0-9]+*"
- adkit-v*.*.*

Check warning on line 12 in .github/workflows/docker-build-and-push-main-self-hosted.yaml

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (adkit)
branches:
- main
schedule:
- cron: 0 0 1,15 * *
workflow_dispatch:
inputs:
artifacts-destination:
type: choice
description: Destination for the artifacts
options:
- registry
- tarball
default: tarball

jobs:
docker-build-and-push-main-self-hosted:
Expand All @@ -21,11 +36,12 @@
include:
- name: no-cuda
base_image_env: base_image
lib_dir: aarch64
setup-args: --no-nvidia
additional-tag-suffix: ""
- name: cuda
base_image_env: cuda_base_image
setup-args: --no-cuda-drivers
base_image_env: base_image
lib_dir: aarch64
additional-tag-suffix: -cuda
steps:
# https://github.com/actions/checkout/issues/211
Expand All @@ -46,18 +62,19 @@
cat arm64.env | sed -e "s/^\s*//" -e "/^#/d" >> $GITHUB_ENV
fi

- name: Build 'autoware-universe'
- name: Build 'autoware-openadk'

Check warning on line 65 in .github/workflows/docker-build-and-push-main-self-hosted.yaml

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (openadk)
uses: ./.github/actions/docker-build-and-push
with:
bake-target: autoware-universe
bake-target: autoware-openadk
build-args: |
*.platform=linux/arm64
*.args.ROS_DISTRO=${{ env.rosdistro }}
*.args.BASE_IMAGE=${{ env[format('{0}', matrix.base_image_env)] }}
*.args.PREBUILT_BASE_IMAGE=${{ env.prebuilt_base_image }}
*.args.SETUP_ARGS=${{ matrix.setup-args }}
tag-prefix: ${{ env.rosdistro }}-
*.args.LIB_DIR=${{ matrix.lib_dir }}
tag-suffix: ${{ matrix.additional-tag-suffix }}-arm64
tag-prefix: ${{ env.rosdistro }}
allow-push: true

- name: Show disk space
run: |
Expand Down
Loading
Loading