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

Adding break build section cache for sync #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion docker_templates/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import string
import hashlib
import re
import string
import urllib.request

# TODO: think of a better version pattern like
Expand Down Expand Up @@ -44,6 +45,12 @@
'ros2_packages': string.Template('ros-$ros2distro_name-$package'),
}

packageInReleaseLookup = {
'gazebo_packages': string.Template('http://packages.osrfoundation.org/gazebo/$os_name-$release/dists/$os_code_name/InRelease'),
'ros_packages': string.Template('http://packages.ros.org/$release/ubuntu/dists/$os_code_name/InRelease'),
'ros2_packages': string.Template('http://repo.ros2.org/$os_name/main/dists/$os_code_name/InRelease'),
}

def getPackageIndex(data, package_index_url):
"""Get current online package index"""

Expand Down Expand Up @@ -105,6 +112,18 @@ def getPackageVersions(data, package_index, packages, package_type):

return package_versions

def getPackageReleaseToken(data, package_release_url):
"""Get package release token"""

# Download package index
req = urllib.request.Request(package_release_url)
with urllib.request.urlopen(req) as response:
package_release = response.read().decode('utf-8')
token = {}
token['date'] = re.search(r'Date: (.*)', package_release).group(1)
token['digest'] = hashlib.sha256(package_release.encode('utf-8')).hexdigest()
return token

def expandPackages(data):
for package_type in indexUrlTemplateLookup:
if package_type in data:
Expand All @@ -113,3 +132,6 @@ def expandPackages(data):
package_index = getPackageIndex(data, package_index_url)
package_versions = getPackageVersions(data, package_index, data[package_type], package_type)
data[package_type] = package_versions
package_inrelease_url_template = packageInReleaseLookup[package_type]
package_inrelease_url = package_inrelease_url_template.substitute(data)
data[package_type + '_token'] = getPackageReleaseToken(data, package_inrelease_url)
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys D2486D2DD8
# setup sources.list
RUN . /etc/os-release \
&& echo "deb http://packages.osrfoundation.org/gazebo/$ID-stable `lsb_release -sc` main" > /etc/apt/sources.list.d/gazebo-latest.list
@[if 'gazebo_packages_token' in locals()]@
@[ if gazebo_packages_token]@

# break build cache for sync
RUN apt-get update \
&& . /etc/os-release \
&& echo "Release: @(gazebo_packages_token['date'])@ " \
&& export SUM=@(gazebo_packages_token['digest'])@ \
&& export FILE=/var/lib/apt/lists/packages.osrfoundation.org_gazebo_$ID-stable_dists_$(lsb_release -sc)_InRelease \
&& echo "$SUM *$FILE" | sha256sum --check \
&& rm -rf /var/lib/apt/lists/*
@[ end if]@
@[end if]@

# install gazebo packages
RUN apt-get update && apt-get install -q -y \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 421C365BD9
# setup sources.list
RUN . /etc/os-release \
&& echo "deb http://repo.ros2.org/$ID/main `lsb_release -sc` main" > /etc/apt/sources.list.d/ros2-latest.list
@[if 'ros2_packages_token' in locals()]@
@[ if ros2_packages_token]@

# break build cache for sync
RUN apt-get update \
&& . /etc/os-release \
&& echo "Release: @(ros2_packages_token['date'])@ " \
&& export SUM=@(ros2_packages_token['digest'])@ \
&& export FILE=/var/lib/apt/lists/repo.ros2.org_ubuntu_main_dists_$(lsb_release -sc)_InRelease \
&& echo "$SUM *$FILE" | sha256sum --check \
&& rm -rf /var/lib/apt/lists/*
@[ end if]@
@[end if]@

# setup environment
ENV LANG C.UTF-8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 421C365BD9

# setup sources.list
RUN echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list
@[if 'ros_packages_token' in locals()]@
@[ if ros_packages_token]@

# break build cache for sync
RUN apt-get update \
&& . /etc/os-release \
&& echo "Release: @(ros_packages_token['date'])@ " \
&& export SUM=@(ros_packages_token['digest'])@ \
&& export FILE=/var/lib/apt/lists/packages.ros.org_ros_ubuntu_dists_$(lsb_release -sc)_InRelease \
&& echo "$SUM *$FILE" | sha256sum --check \
&& rm -rf /var/lib/apt/lists/*
@[ end if]@
@[end if]@

# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
Expand Down