-
Notifications
You must be signed in to change notification settings - Fork 6
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
Separate focal and jammy carma-base Dockerfiles #191
Changes from 23 commits
e34893b
557f9ef
99eab19
8637c62
26ed51d
ee0227b
bc391ce
3e3cb47
0112dbf
8a5b129
043038a
edc611c
0e37369
44794a3
a93f61b
4c1934b
6d56295
fe099bc
e2b0ea6
1fd5550
e73bbd2
723a731
f4bb43a
f97d1c6
8f7ad45
2d34068
42b3fd0
af87762
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
# This workflow will only build for Pull Requests which are opened, changed , merged | ||
name: Docker build | ||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
docker: | ||
uses: usdot-fhwa-stol/actions/.github/workflows/docker.yml@main | ||
# This workflow will only build for Pull Requests which are opened, changed , merged | ||
name: Docker build | ||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
# Jammy 22.04 (ROS2 Humble) | ||
docker-build-jammy: | ||
uses: usdot-fhwa-stol/actions/.github/workflows/docker.yml@main | ||
with: | ||
file: ./jammy/Dockerfile | ||
# Focal 20.04 (ROS1 Noetic/ ROS2 Foxy) | ||
docker-build-focal: | ||
uses: usdot-fhwa-stol/actions/.github/workflows/docker.yml@main | ||
with: | ||
file: ./focal/Dockerfile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
# This workflow will build and push official docker images when new push occurs to develop, master, release branches but doesn't run any unit test or sonar scanner | ||
name: Docker Hub build | ||
on: | ||
push: | ||
branches: | ||
- develop | ||
- master | ||
- "release/*" | ||
tags: | ||
- "carma-system-*" | ||
jobs: | ||
dockerhub: | ||
uses: usdot-fhwa-stol/actions/.github/workflows/dockerhub.yml@main | ||
secrets: | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | ||
# This workflow will build and push official docker images when new push occurs to develop, master, release branches but doesn't run any unit test or sonar scanner | ||
name: Docker Hub build | ||
on: | ||
push: | ||
branches: | ||
- develop | ||
- master | ||
- "release/*" | ||
tags: | ||
- "carma-system-*" | ||
jobs: | ||
dockerhub-focal: | ||
uses: usdot-fhwa-stol/actions/.github/workflows/dockerhub.yml@main | ||
secrets: | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | ||
with: | ||
file: ./focal/Dockerfile | ||
# TODO: add focal suffix when humble is migrated | ||
#tag_name_suffix: focal https://usdot-carma.atlassian.net/browse/ARC-227 | ||
dockerhub-jammy: | ||
uses: usdot-fhwa-stol/actions/.github/workflows/dockerhub.yml@main | ||
secrets: | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | ||
with: | ||
file: ./jammy/Dockerfile | ||
tag_name_suffix: jammy |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (C) 2018-2021 LEIDOS. | ||
# Copyright (C) 2018-2024 LEIDOS. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
|
@@ -13,10 +13,11 @@ | |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
set -x | ||
|
||
USERNAME=usdotfhwastol | ||
BRANCH=$(git rev-parse --abbrev-ref HEAD) | ||
BUILD_FOCAL=false | ||
BUILD_JAMMY=false | ||
|
||
cd "$(dirname "$0")" | ||
IMAGE=$(basename `git rev-parse --show-toplevel`) | ||
|
@@ -34,7 +35,8 @@ while [[ $# -gt 0 ]]; do | |
shift | ||
;; | ||
--system-release) | ||
SYSTEM_RELEASE=true | ||
USERNAME=usdotfhwastol | ||
COMPONENT_VERSION_STRING=$("./get-system-version.sh") | ||
shift | ||
;; | ||
-p|--push) | ||
|
@@ -56,42 +58,68 @@ while [[ $# -gt 0 ]]; do | |
fi | ||
shift | ||
;; | ||
--focal) | ||
BUILD_FOCAL=true | ||
shift | ||
;; | ||
--jammy) | ||
BUILD_JAMMY=true | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
if [[ -z "$COMPONENT_VERSION_STRING" ]]; then | ||
COMPONENT_VERSION_STRING=$("./get-component-version.sh") | ||
fi | ||
|
||
echo "Building docker image for $IMAGE version: $COMPONENT_VERSION_STRING" | ||
echo "Final image name: $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING" | ||
build_image() { | ||
local dockerfile_path=$1 | ||
local tag_suffix=$2 | ||
|
||
cd .. | ||
docker build --network=host --no-cache -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING \ | ||
--build-arg VERSION="$COMPONENT_VERSION_STRING" \ | ||
--build-arg VCS_REF=`git rev-parse --short HEAD` \ | ||
--build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` . | ||
echo "Building docker image for $IMAGE version: $COMPONENT_VERSION_STRING using Dockerfile: $dockerfile_path" | ||
echo "Final image name: $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING$tag_suffix" | ||
|
||
DOCKER_BUILDKIT=1 docker build --network=host -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING$tag_suffix \ | ||
--build-arg VERSION="$COMPONENT_VERSION_STRING" \ | ||
--build-arg VCS_REF=`git rev-parse --short HEAD` \ | ||
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ | ||
-f $dockerfile_path . | ||
|
||
TAGS+=("$USERNAME/$IMAGE:$COMPONENT_VERSION_STRING$tag_suffix") | ||
|
||
docker tag $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING$tag_suffix $USERNAME/$IMAGE:latest$tag_suffix | ||
TAGS+=("$USERNAME/$IMAGE:latest$tag_suffix") | ||
|
||
echo "Tagged $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING$tag_suffix as $USERNAME/$IMAGE:latest$tag_suffix" | ||
} | ||
|
||
TAGS=() | ||
TAGS+=("$USERNAME/$IMAGE:$COMPONENT_VERSION_STRING") | ||
|
||
docker tag $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING $USERNAME/$IMAGE:latest | ||
TAGS+=("$USERNAME/$IMAGE:latest") | ||
cd .. | ||
|
||
# If neither --focal nor --jammy is specified, build both | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are currently just starting to update the systems to include jammy, it would make more sense to me for this to default to just building focal. Open to discussion on this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. I will turn it off by default. |
||
if [ "$BUILD_FOCAL" = false ] && [ "$BUILD_JAMMY" = false ]; then | ||
BUILD_FOCAL=true | ||
BUILD_JAMMY=true | ||
fi | ||
|
||
echo "Tagged $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING as $USERNAME/$IMAGE:latest" | ||
# TODO, distinguish with suffix when Humble is fully integrated | ||
# until then focal will have no suffix and be the main image | ||
# https://usdot-carma.atlassian.net/browse/ARC-227 | ||
if [ "$BUILD_FOCAL" = true ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add echo "Building Focal Image..." and echo "Building Jammy Image..." some thing like that which is easy to debug during CI for each focal and jammy ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
build_image "focal/Dockerfile" "" #replace with "-focal" | ||
fi | ||
|
||
if [ "$SYSTEM_RELEASE" = true ]; then | ||
SYSTEM_VERSION_STRING=$("./get-system-version.sh") | ||
docker tag $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING $USERNAME/$IMAGE:$SYSTEM_VERSION_STRING | ||
echo "Tagged $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING as $USERNAME/$IMAGE:$SYSTEM_VERSION_STRING" | ||
TAGS+=("$USERNAME/$IMAGE:$SYSTEM_VERSION_STRING") | ||
if [ "$BUILD_JAMMY" = true ]; then | ||
build_image "jammy/Dockerfile" "-jammy" | ||
fi | ||
|
||
if [ "$PUSH" = true ]; then | ||
for tag in $TAGS; do | ||
for tag in "${TAGS[@]}"; do | ||
docker push "${tag}" | ||
done | ||
fi | ||
|
||
echo "" | ||
echo "##### $IMAGE Docker Image Build Done! #####" | ||
echo "##### $IMAGE Docker Image Build Done! #####" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (C) 2018-2021 LEIDOS. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
|
||
cd "$(dirname "$0")" | ||
cd .. | ||
COMPONENT_TAG_PREFIX="${PWD##*/}" | ||
git describe --all --match="$COMPONENT_TAG_PREFIX*" --always --dirty="-SNAPSHOT" | awk -F "/" '{print $NF}' | sed "s/$COMPONENT_TAG_PREFIX\_//" | ||
|
||
# Copyright (C) 2018-2024 LEIDOS. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
|
||
# Change to the directory containing the script | ||
cd "$(dirname "$0")" | ||
|
||
# Move up one directory (likely to the root of the project) | ||
cd .. | ||
|
||
# Get the last commit message | ||
COMMIT_MSG=$(git log -1 --pretty=%B) | ||
|
||
# Remove newlines and special characters, replace spaces with underscores | ||
VERSION=$(echo "$COMMIT_MSG" | tr -d '\n' | tr -dc '[:alnum:][:space:]' | tr '[:space:]' '_') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so the version is generated from the commit message, which works well for general versioning should we consider appending a suffix like -focal or -jammy to the VERSION variable depending on which image is being built (focal or jammy)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The suffix is appended outside this function through variable called $tag_suffix. So it should be good. |
||
|
||
# Limit the length of the version string (e.g., to 50 characters) | ||
VERSION="${VERSION:0:50}" | ||
|
||
# Append -SNAPSHOT if there are uncommitted changes | ||
if [[ -n $(git status -s) ]]; then | ||
VERSION="${VERSION}-SNAPSHOT" | ||
fi | ||
|
||
echo "$VERSION" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (C) 2018-2021 LEIDOS. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
|
||
# Intialize the CARMA environment by sourcing the necessary ROS shell scripts | ||
# then run whatever string is passed as argument to this script in that | ||
# initialized context. E.g. "entrypoint.sh roslaunch carma carma_docker.launch" | ||
# runs "roslaunch carma carma_docker.launch" after setting up the environment | ||
# such that ROS and CARMA are on the user's PATH | ||
|
||
if [ $# -eq 0 ]; then | ||
# If no other command is passed to this script, run bash | ||
source ~/.base-image/init-env.sh; exec "bash" | ||
else | ||
source ~/.base-image/init-env.sh; exec "$@" | ||
fi | ||
#!/bin/bash | ||
# Copyright (C) 2018-2021 LEIDOS. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
# Intialize the CARMA environment by sourcing the necessary ROS shell scripts | ||
# then run whatever string is passed as argument to this script in that | ||
# initialized context. E.g. "entrypoint.sh roslaunch carma carma_docker.launch" | ||
# runs "roslaunch carma carma_docker.launch" after setting up the environment | ||
# such that ROS and CARMA are on the user's PATH | ||
if [ $# -eq 0 ]; then | ||
# If no other command is passed to this script, run bash | ||
source ~/.base-image/init-env.sh; exec "bash" | ||
else | ||
source ~/.base-image/init-env.sh; exec "$@" | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the two jobs triggered when changes are pushed ? May be can we use this path filters (https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onpushpull_requestpaths) to only run specific job that is required when its associated files changed instead of running multiple jobs every time ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes great point I forgot. I tried adding those. I had to separate the yml files to write it cleanly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the change by creating a dummy PR here that points to this branch. The dummy PR only has jammy changes, which successfully only triggered jammy docker: https://github.com/usdot-fhwa-stol/carma-base/actions/runs/11247485262/job/31271050955?pr=192