Skip to content

Commit

Permalink
feat(docker): re-organize the autoware docker containers (autowarefou…
Browse files Browse the repository at this point in the history
…ndation#4072)

Signed-off-by: oguzkaganozt <[email protected]>
  • Loading branch information
oguzkaganozt authored Mar 6, 2024
1 parent e6dc52c commit da22bdc
Show file tree
Hide file tree
Showing 73 changed files with 1,335 additions and 718 deletions.
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
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined",
"--net=host",
"--volume=/etc/localtime:/etc/localtime:ro"
],
"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

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",
"--security-opt",
"seccomp=unconfined",
"--net=host",
"--volume=/etc/localtime:/etc/localtime:ro",
"--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 @@ jobs:
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 @@ jobs:
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

Check warning on line 68 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)
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

0 comments on commit da22bdc

Please sign in to comment.