Skip to content

Commit 14b1844

Browse files
authored
Merge pull request #764 from joshcooper/private_apt
Update module to support apt-puppetcore.puppet.com
2 parents 60e3526 + a3e3c5e commit 14b1844

File tree

9 files changed

+274
-61
lines changed

9 files changed

+274
-61
lines changed

docker/bin/helpers/run-install.sh

+14-11
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ if [[ -z "${to_version}" ]]; then
77
echo "$0: The version to install must be passed as an argument"
88
exit 1
99
fi
10+
to_collection="$2"
1011
puppet_version=( ${to_version//./ } )
1112
puppet_major=${puppet_version[0]}
12-
case $puppet_major in
13-
7)
14-
to_collection=puppetcore7
15-
;;
16-
8)
17-
to_collection=puppetcore8
18-
;;
19-
*)
20-
echo "$0: Invalid version supplied" 1>&2
21-
exit 1
22-
esac
13+
if [[ -z "$to_collection" ]]; then
14+
case $puppet_major in
15+
7)
16+
to_collection=puppetcore7
17+
;;
18+
8)
19+
to_collection=puppetcore8
20+
;;
21+
*)
22+
echo "$0: Invalid version supplied" 1>&2
23+
exit 1
24+
esac
25+
fi
2326

2427
export PT__installdir=../
2528
export PT_version=${to_version}

docker/bin/install.sh

+30-28
Original file line numberDiff line numberDiff line change
@@ -27,48 +27,50 @@ fi
2727
cd "$(dirname "$0")/../.."
2828
platforms=${1:-rocky}
2929
version=${2:-8.11.0}
30+
collection=${3:-puppetcore8}
3031
for platform in ${platforms//,/ }
3132
do
32-
dockerfile='docker/install/dnf/Dockerfile'
33-
3433
case $platform in
35-
amazon*)
36-
base_image='amazonlinux:2023'
37-
;;
38-
39-
fedora40)
40-
base_image='fedora:40'
41-
;;
42-
43-
fedora36)
44-
base_image='fedora:36'
45-
;;
46-
47-
fedora*)
48-
base_image='fedora:41'
49-
;;
50-
51-
rocky8)
52-
base_image='rockylinux/rockylinux:8'
34+
amazon*|fedora*|rocky*)
35+
dockerfile='docker/install/dnf/Dockerfile'
5336
;;
54-
55-
rocky*)
56-
base_image='rockylinux/rockylinux:9'
57-
;;
58-
5937
sles*)
60-
base_image='registry.suse.com/suse/sle15:15.6'
6138
dockerfile='docker/install/sles/Dockerfile'
6239
;;
40+
debian*|ubuntu*)
41+
dockerfile='docker/install/apt/Dockerfile'
42+
;;
43+
*)
44+
echo "$0: platform ${platform} is not supported"
45+
exit 1
46+
;;
47+
esac
6348

49+
# Default to the latest OS version for each distro
50+
case $platform in
51+
amazon*) base_image='amazonlinux:2023';;
52+
fedora36) base_image='fedora:36';;
53+
fedora40) base_image='fedora:40';;
54+
fedora*) base_image='fedora:41';;
55+
rocky8) base_image='rockylinux/rockylinux:8';;
56+
rocky*) base_image='rockylinux/rockylinux:9';;
57+
sles*) base_image='registry.suse.com/suse/sle15:15.6';;
58+
debian10) base_image='debian:buster';;
59+
debian11) base_image='debian:bullseye';;
60+
debian*) base_image='debian:bookworm';;
61+
ubuntu1804) base_image='ubuntu:bionic';;
62+
ubuntu2004) base_image='ubuntu:focal';;
63+
ubuntu2204) base_image='ubuntu:jammy';;
64+
ubuntu*) base_image='ubuntu:noble';;
6465
*)
65-
echo "$0: Usage install.sh [amazon|fedora|rocky|sles]"
66+
echo "$0: Usage install.sh [amazon|debian|fedora|rocky|sles|ubuntu]"
6667
exit 1
6768
;;
6869
esac
6970

71+
# Add "--progress plain" for complete build output
7072
docker build --rm -f "${dockerfile}" . -t pa-dev:$platform.install \
7173
--build-arg BASE_IMAGE="${base_image}"
72-
docker run -e PUPPET_FORGE_TOKEN --rm -ti pa-dev:$platform.install "${version}"
74+
docker run -e PUPPET_FORGE_TOKEN --rm -ti pa-dev:$platform.install "${version}" "${collection}"
7375
done
7476
echo Complete

docker/bin/upgrade.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,25 @@ do
5656
dockerfile='docker/upgrade/sles/Dockerfile'
5757
;;
5858

59+
debian)
60+
base_image='debian:bookworm'
61+
release_package='https://apt.puppet.com/puppet7-release-bookworm.deb'
62+
dockerfile='docker/upgrade/apt/Dockerfile'
63+
;;
64+
65+
ubuntu)
66+
base_image='ubuntu:jammy'
67+
release_package='https://apt.puppet.com/puppet7-release-jammy.deb'
68+
dockerfile='docker/upgrade/apt/Dockerfile'
69+
;;
70+
5971
*)
60-
echo "$0: Usage upgrade.sh [amazon|fedora|rocky|sles] [before] [after]"
72+
echo "$0: Usage upgrade.sh [amazon|debian|fedora|rocky|sles|ubuntu] [before] [after]"
6173
exit 1
6274
;;
6375
esac
6476

77+
# Add "--progress plain" for complete build output
6578
docker build --rm -f ${dockerfile} . -t pa-dev:$platform \
6679
--build-arg before=${before} \
6780
--build-arg BASE_IMAGE=${base_image} \

docker/install/apt/Dockerfile

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# This Dockerfile enables an iterative development workflow where you can make
2+
# a change and test it out quickly. The majority of commands in this file will
3+
# be cached, making the feedback loop typically quite short. The workflow is
4+
# as follows:
5+
# 1. Set up pre-conditions for the system in puppet code using `deploy.pp`.
6+
# 2. Make a change to the module.
7+
# 3. Run `./docker/bin/install.sh ubuntu` from the project directory.
8+
# 4. Review the output. Repeat steps 2-3 as needed.
9+
#
10+
# At the end of execution, you will see a line like:
11+
#
12+
# REMIND
13+
14+
ARG BASE_IMAGE=ubuntu:noble
15+
FROM ${BASE_IMAGE}
16+
17+
# Use this to force a cache reset (e.g. for output purposes)
18+
#COPY $0 /tmp/Dockerfile
19+
20+
# Install some other dependencies for ease of life.
21+
RUN apt-get update \
22+
&& DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y wget git lsb-release apt-utils systemd \
23+
&& rm -rf /var/lib/apt/lists/*
24+
25+
26+
# This is also duplicated in docker/bin/helpers/run-upgrade.sh.
27+
ENV module_path=/tmp/modules
28+
WORKDIR "${module_path}/puppet_agent"
29+
COPY metadata.json ./
30+
31+
# Installing dependencies from source. These versions should be within the range
32+
# of `dependencies` in metadata.json.
33+
RUN git clone --tags https://github.com/puppetlabs/puppetlabs-stdlib ../stdlib && \
34+
$(cd ../stdlib && git checkout $(git describe --tags $(git rev-list --tags --max-count=1)))
35+
RUN git clone --tags https://github.com/puppetlabs/puppetlabs-inifile ../inifile && \
36+
$(cd ../inifile && git checkout $(git describe --tags $(git rev-list --tags --max-count=1)))
37+
RUN git clone --tags https://github.com/puppetlabs/puppetlabs-apt ../apt && \
38+
$(cd ../apt && git checkout $(git describe --tags $(git rev-list --tags --max-count=1)))
39+
RUN git clone --tags https://github.com/puppetlabs/puppetlabs-facts ../facts && \
40+
$(cd ../facts && git checkout $(git describe --tags $(git rev-list --tags --max-count=1)))
41+
42+
# Now move the project directory's files into the image. That way, if these
43+
# files change, caching will skip everything before this.
44+
COPY docker/bin/helpers/run-install.sh /tmp/bin/run-install.sh
45+
COPY files/ ./files/
46+
COPY locales/ ./locales/
47+
COPY spec/ ./spec/
48+
COPY task_spec/ ./task_spec/
49+
COPY tasks/ ./tasks/
50+
COPY templates/ ./templates
51+
COPY types/ ./types/
52+
COPY Gemfile Gemfile.lock Rakefile ./
53+
COPY lib/ ./lib/
54+
COPY manifests/ ./manifests/
55+
56+
# Perform the install.
57+
ENTRYPOINT ["/tmp/bin/run-install.sh"]

docker/upgrade/apt/Dockerfile

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# This Dockerfile enables an iterative development workflow where you can make
2+
# a change and test it out quickly. The majority of commands in this file will
3+
# be cached, making the feedback loop typically quite short. The workflow is
4+
# as follows:
5+
# 1. Set up pre-conditions for the system in puppet code using `deploy.pp`.
6+
# 2. Make a change to the module.
7+
# 3. Run `docker build -f docker/Dockerfile .` or
8+
# `./docker/bin/upgrade.sh rocky` from the project directory. If you would
9+
# like to test specific version upgrades, you can add run this like so:
10+
# `docker build -f docker/rocky/Dockerfile . \
11+
# -t pa-dev:rocky --build-arg before=1.10.14`
12+
# 4. Upgrade the container by running the image:
13+
# `docker run -it pa-dev:rocky`
14+
# Specify your upgrade TO version as an argument to the `docker run`
15+
# command.
16+
# 5. Review the output. Repeat steps 2-5 as needed.
17+
#
18+
# At the end of execution, you will see a line like:
19+
#
20+
# Notice: /Stage[main]/Puppet_agent::Install/Package[puppet-agent]/ensure: ensure changed '1.10.14-1.el8' to '6.2.0'
21+
#
22+
# This specifies the versions that were used for upgrade.
23+
#
24+
# Arguments:
25+
# - before: The version to do upgrade FROM. Default: "7.34.0"
26+
27+
ARG BASE_IMAGE=ubuntu:noble
28+
FROM ${BASE_IMAGE}
29+
30+
# Use this to force a cache reset (e.g. for output purposes)
31+
#COPY $0 /tmp/Dockerfile
32+
33+
# Install some other dependencies for ease of life.
34+
RUN apt-get update \
35+
&& DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y wget git lsb-release apt-utils systemd gnupg \
36+
&& rm -rf /var/lib/apt/lists/*
37+
38+
ARG before=7.34.0
39+
LABEL before=${before}
40+
41+
ARG RELEASE_PACKAGE
42+
43+
RUN apt-get update \
44+
&& apt install -y curl \
45+
&& rm -rf /var/lib/apt/lists/*
46+
47+
# Install proper FROM repo pupet 7
48+
RUN curl -L -o puppet7.deb ${RELEASE_PACKAGE} \
49+
&& dpkg -i puppet7.deb
50+
51+
# Print out which versions of the puppet-agent package are available (for reference).
52+
#RUN dnf list puppet-agent --showduplicates
53+
54+
# Install FROM version of puppet-agent.
55+
RUN apt-get update \
56+
&& apt list -a puppet-agent \
57+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y puppet-agent \
58+
&& rm -rf /var/lib/apt/lists/*
59+
60+
# This is also duplicated in the docker/bin/helpers/run-upgrade.sh.
61+
ENV module_path=/tmp/modules
62+
WORKDIR "${module_path}/puppet_agent"
63+
COPY metadata.json ./
64+
65+
# Installing dependencies from source. These versions should be within the range
66+
# of `dependencies` in metadata.json.
67+
RUN git clone --tags https://github.com/puppetlabs/puppetlabs-stdlib ../stdlib && \
68+
$(cd ../stdlib && git checkout $(git describe --tags $(git rev-list --tags --max-count=1)))
69+
RUN git clone --tags https://github.com/puppetlabs/puppetlabs-inifile ../inifile && \
70+
$(cd ../inifile && git checkout $(git describe --tags $(git rev-list --tags --max-count=1)))
71+
RUN git clone --tags https://github.com/puppetlabs/puppetlabs-apt ../apt && \
72+
$(cd ../apt && git checkout $(git describe --tags $(git rev-list --tags --max-count=1)))
73+
RUN git clone --tags https://github.com/puppetlabs/puppetlabs-facts ../facts && \
74+
$(cd ../facts && git checkout $(git describe --tags $(git rev-list --tags --max-count=1)))
75+
76+
# Check that all dependencies are installed.
77+
RUN /opt/puppetlabs/puppet/bin/puppet module --modulepath $module_path list --tree
78+
COPY docker/deploy.pp /tmp/deploy.pp
79+
RUN ["sh", "-c", "/opt/puppetlabs/puppet/bin/puppet apply --modulepath $module_path /tmp/deploy.pp"]
80+
81+
# Now move the project directory's files into the image. That way, if these
82+
# files change, caching will skip everything before this.
83+
COPY docker/bin/helpers/run-upgrade.sh /tmp/bin/run-upgrade.sh
84+
COPY files/ ./files/
85+
COPY locales/ ./locales/
86+
COPY spec/ ./spec/
87+
COPY task_spec/ ./task_spec/
88+
COPY tasks/ ./tasks/
89+
COPY templates/ ./templates
90+
COPY types/ ./types/
91+
COPY Gemfile Gemfile.lock Rakefile ./
92+
COPY lib/ ./lib/
93+
COPY manifests/ ./manifests/
94+
95+
COPY docker/upgrade.pp /tmp/upgrade.pp
96+
97+
# Print out which versions of the puppet-agent package are available (for reference).
98+
#RUN yum list puppet-agent --showduplicates
99+
100+
# Perform the upgrade.
101+
ENTRYPOINT ["/tmp/bin/run-upgrade.sh"]

files/puppet-keyring.gpg

2.24 KB
Binary file not shown.

manifests/osfamily/debian.pp

+25-4
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,39 @@
6666
ensure => absent,
6767
priority => '90',
6868
}
69+
} elsif $puppet_agent::collection =~ /core/ {
70+
$source = 'https://apt-puppetcore.puppet.com'
6971
} else {
7072
$source = $puppet_agent::apt_source
7173
}
7274

73-
$keyname = 'GPG-KEY-puppet-20250406'
75+
$repo_username = getvar('puppet_agent::username')
76+
$repo_password = unwrap(getvar('puppet_agent::password'))
77+
78+
if $repo_username and $repo_password {
79+
# lint:ignore:strict_indent
80+
file { "/etc/apt/auth.conf.d/apt-${puppet_agent::collection}-puppet.conf":
81+
ensure => file,
82+
owner => 0,
83+
group => 0,
84+
mode => '0600',
85+
content => Sensitive(@("EOT"))
86+
machine ${source}
87+
login ${repo_username}
88+
password ${repo_password}
89+
| EOT
90+
}
91+
# lint:endignore
92+
}
93+
94+
$keyname = 'puppet-keyring.gpg'
7495

7596
apt::source { 'pc_repo':
7697
location => $source,
77-
repos => $puppet_agent::collection,
98+
repos => regsubst($puppet_agent::collection, /core/, ''),
7899
key => {
79-
'name' => "${keyname}.asc",
80-
'content' => file("${module_name}/${keyname}"),
100+
'name' => $keyname,
101+
'source' => "puppet:///modules/${module_name}/${keyname}",
81102
},
82103
notify => Exec['pc_repo_force'],
83104
}

spec/classes/puppet_agent_osfamily_debian_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@
155155
'location' => 'https://master.example.vm:8140/packages/2000.0.0/debian-7-x86_64',
156156
'repos' => 'PC1',
157157
'key' => {
158-
'name' => 'GPG-KEY-puppet-20250406.asc',
159-
'content' => Puppet::FileSystem.read_preserve_line_endings('files/GPG-KEY-puppet-20250406'),
158+
'name' => 'puppet-keyring.gpg',
159+
'source' => 'puppet:///modules/puppet_agent/puppet-keyring.gpg',
160160
},
161161
})
162162
}
@@ -177,8 +177,8 @@
177177
'location' => 'https://fake-apt-mirror.com/packages/2000.0.0/debian-7-x86_64',
178178
'repos' => 'PC1',
179179
'key' => {
180-
'name' => 'GPG-KEY-puppet-20250406.asc',
181-
'content' => Puppet::FileSystem.read_preserve_line_endings('files/GPG-KEY-puppet-20250406'),
180+
'name' => 'puppet-keyring.gpg',
181+
'source' => 'puppet:///modules/puppet_agent/puppet-keyring.gpg',
182182
},
183183
})
184184
}
@@ -218,8 +218,8 @@
218218
'location' => 'https://apt.puppet.com',
219219
'repos' => 'puppet5',
220220
'key' => {
221-
'name' => 'GPG-KEY-puppet-20250406.asc',
222-
'content' => Puppet::FileSystem.read_preserve_line_endings('files/GPG-KEY-puppet-20250406'),
221+
'name' => 'puppet-keyring.gpg',
222+
'source' => 'puppet:///modules/puppet_agent/puppet-keyring.gpg',
223223
},
224224
})
225225
}
@@ -241,8 +241,8 @@
241241
'location' => 'https://fake-apt-mirror.com/',
242242
'repos' => 'puppet5',
243243
'key' => {
244-
'name' => 'GPG-KEY-puppet-20250406.asc',
245-
'content' => Puppet::FileSystem.read_preserve_line_endings('files/GPG-KEY-puppet-20250406'),
244+
'name' => 'puppet-keyring.gpg',
245+
'source' => 'puppet:///modules/puppet_agent/puppet-keyring.gpg',
246246
},
247247
})
248248
}

0 commit comments

Comments
 (0)