Skip to content

Commit

Permalink
Merge pull request #67 from osrf/template_eol
Browse files Browse the repository at this point in the history
Snippet for setting up APT repos based on if the distro is EOL or not
  • Loading branch information
mikaelarguedas authored Aug 1, 2019
2 parents 8ce46b4 + 49cc868 commit 1575819
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 23 deletions.
53 changes: 53 additions & 0 deletions docker_templates/eol_distro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2019 Mikael Arguedas
#
# 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.

def isDistroEOL(ros_distro_name, os_distro_name):
eol_ros_distros = [
# ROS 1
'boxturtle',
'cturtle',
'diamondback',
'electric',
'fuerte',
'groovy',
'hydro',
'indigo',
'jade',
'lunar',
# ROS 2
'ardent',
]
eol_base_images = [
# Ubuntu
'lucid',
'maverick',
'natty',
'oneiric',
'precise',
'quantal',
'raring',
'saucy',
'trusty',
'utopic',
'vivid',
'wily',
'yakkety',
'zesty',
'artful',
'cosmic',
# Debian
'wheezy',
'jessie',
]
return os_distro_name in eol_base_images or ros_distro_name in eol_ros_distros
16 changes: 15 additions & 1 deletion docker_templates/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import re
import urllib.request

from docker_templates.eol_distro import isDistroEOL

# TODO: think of a better version pattern like
# r'\d(?!Version\:\s)(.+)(?=(~\w+\n))' but works without a trailing ~
version_pattern = r'(?<=Version: )\d+\.\d+\.\d+\-\d+'
Expand All @@ -30,6 +32,8 @@
'gazebo_packages': string.Template('http://packages.osrfoundation.org/gazebo/$os_name-$release/dists/$os_code_name/main/binary-$arch/Packages'),
'ros_packages': string.Template('http://packages.ros.org/ros/ubuntu/dists/$os_code_name/main/binary-$arch/Packages'),
'ros2_packages': string.Template('http://packages.ros.org/ros2/ubuntu/dists/$os_code_name/main/binary-$arch/Packages'),
'ros_packages_snapshots': string.Template('http://snapshots.ros.org/$rosdistro_name/final/ubuntu/dists/$os_code_name/main/binary-$arch/Packages'),
'ros2_packages_snapshots': string.Template('http://snapshots.ros.org/$ros2distro_name/final/ubuntu/dists/$os_code_name/main/binary-$arch/Packages'),
}

packageNameVersionTemplateLookup = {
Expand Down Expand Up @@ -108,7 +112,17 @@ def getPackageVersions(data, package_index, packages, package_type):
def expandPackages(data):
for package_type in indexUrlTemplateLookup:
if package_type in data:
package_index_url_template = indexUrlTemplateLookup[package_type]
# determine if distro is eol and apply the appropriate index URL template
ros_distro_name = ''
if package_type == 'ros_packages':
ros_distro_name = data['rosdistro_name']
elif package_type == 'ros2_packages':
ros_distro_name = data['ros2distro_name']
eol = isDistroEOL(ros_distro_name, data['os_code_name'])
if eol:
package_index_url_template = indexUrlTemplateLookup[package_type + '_snapshots']
else:
package_index_url_template = indexUrlTemplateLookup[package_type]
package_index_url = package_index_url_template.substitute(data)
package_index = getPackageIndex(data, package_index_url)
package_versions = getPackageVersions(data, package_index, data[package_type], package_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
maintainer_name=maintainer_name,
))@
@
@(TEMPLATE(
'snippet/old_release_set.Dockerfile.em',
template_packages=template_packages,
os_name=os_name,
os_code_name=os_code_name,
))@
@
@(TEMPLATE(
'snippet/setup_tzdata.Dockerfile.em',
os_name=os_name,
Expand All @@ -24,7 +31,6 @@
template_dependencies = [
'dirmngr',
'gnupg2',
'lsb-release',
]
}@
@(TEMPLATE(
Expand All @@ -33,11 +39,13 @@ template_dependencies = [
upstream_packages=upstream_packages if 'upstream_packages' in locals() else [],
))@
@
# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

# setup sources.list
RUN echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list
@(TEMPLATE(
'snippet/setup_ros_sources.Dockerfile.em',
os_name=os_name,
os_code_name=os_code_name,
rosdistro_name=rosdistro_name,
ros_version=ros_version,
))@

@(TEMPLATE(
'snippet/install_ros_bootstrap_tools.Dockerfile.em',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ RUN apt-get update && apt-get install -y --no-install-recommends \

@[ end if]@
@[end if]@
# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys AD19BAB3CBF125EA

# setup sources.list
RUN echo "deb http://snapshots.ros.org/@rosdistro_name/final/@os_name @os_code_name main" > /etc/apt/sources.list.d/ros-snapshots.list
@
@(TEMPLATE(
'snippet/setup_ros_sources.Dockerfile.em',
os_name=os_name,
os_code_name=os_code_name,
rosdistro_name=rosdistro_name,
ros_version=ros_version,
))@

# setup environment
RUN locale-gen en_US.UTF-8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@
base_image=base_image,
maintainer_name=maintainer_name,
))@
@
@(TEMPLATE(
'snippet/old_release_set.Dockerfile.em',
template_packages=template_packages,
os_name=os_name,
os_code_name=os_code_name,
))@
@
@(TEMPLATE(
'snippet/setup_tzdata.Dockerfile.em',
os_name=os_name,
os_code_name=os_code_name,
))@
@
@{
template_dependencies = [
'dirmngr',
'gnupg2',
'lsb-release',
]
# add 'python3-pip' to 'template_dependencies' if pip dependencies are declared
if 'pip3_install' in locals():
Expand All @@ -35,11 +43,14 @@ if 'pip3_install' in locals():
upstream_packages=upstream_packages if 'upstream_packages' in locals() else [],
))@
@
# setup ros2 keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

# setup sources.list
RUN echo "deb http://packages.ros.org/ros2/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros2-latest.list
@(TEMPLATE(
'snippet/setup_ros_sources.Dockerfile.em',
os_name=os_name,
os_code_name=os_code_name,
ros2distro_name=ros2distro_name,
rosdistro_name='',
ros_version=ros_version,
))@

@(TEMPLATE(
'snippet/install_ros_bootstrap_tools.Dockerfile.em',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ RUN pip3 install -U \
@[ end if]@
@[end if]@

# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 421C365BD9FF1F717815A3895523BAEEB01FA116

# setup sources.list
RUN echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list
@(TEMPLATE(
'snippet/setup_ros_sources.Dockerfile.em',
os_name=os_name,
os_code_name=os_code_name,
rosdistro_name=rosdistro_name,
ros_version='1',
))@

ENV ROS1_DISTRO @rosdistro_name
ENV ROS2_DISTRO @ros2distro_name
Expand Down
32 changes: 32 additions & 0 deletions docker_templates/templates/snippet/setup_ros_sources.Dockerfile.em
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@{
import os

from docker_templates.eol_distro import isDistroEOL
if int(ros_version) == 2:
ros_distro_name = ros2distro_name
elif int(ros_version) == 1:
ros_distro_name = rosdistro_name

if isDistroEOL(ros_distro_name, os_code_name):
repo_url = os.path.join(
'http://snapshots.ros.org',
str(ros_distro_name),
'final',
str(os_name)
)
repo_key = 'AD19BAB3CBF125EA'
source_suffix = 'snapshots'
else:
repo_key = 'C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654'
source_suffix = 'latest'

if int(ros_version) == 1:
repo_url = 'http://packages.ros.org/ros/ubuntu'
elif int(ros_version) == 2:
repo_url = 'http://packages.ros.org/ros2/ubuntu'
}@
# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys @(repo_key)

# setup sources.list
RUN echo "deb @(repo_url) @(os_code_name) main" > /etc/apt/sources.list.d/ros@(ros_version)-@(source_suffix).list

0 comments on commit 1575819

Please sign in to comment.