Skip to content

Commit 1c6ff83

Browse files
committed
Install rpm packages from yum-puppetcore.puppet.com
Change the default yum_source to https://yum-puppetcore.puppet.com. Note the change to HTTPS. Add optional username and password to install task. If installing from the default yum_source, then the username defaults to forge-key and a password must be specified. For SLES, add the credentials to /etc/zypp/credentials.d/PuppetcoreCreds For other rpm platforms, add the credentials to the baseurl. Create dnf and sles Dockerfiles for testing the install task. Create install.sh script to build docker image and run it: docker/bin/install.sh [image] [version] By default install 8.11.0 on rocky8. The `PUPPET_FORGE_TOKEN` environment variable must be set, which will be passed as the `password` to the task.
1 parent e629f5c commit 1c6ff83

File tree

7 files changed

+269
-4
lines changed

7 files changed

+269
-4
lines changed

docker/bin/helpers/run-install.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
to_version="${1}"
6+
if [[ -z "${to_version}" ]]; then
7+
echo "$0: The version to install must be passed as an argument"
8+
exit 1
9+
fi
10+
puppet_version=( ${to_version//./ } )
11+
puppet_major=${puppet_version[0]}
12+
case $puppet_major in
13+
7)
14+
to_collection=puppet7
15+
;;
16+
8)
17+
to_collection=puppet8
18+
;;
19+
*)
20+
echo "$0: Invalid version supplied" 1>&2
21+
exit 1
22+
esac
23+
24+
export PT__installdir=../
25+
export PT_version=${to_version}
26+
export PT_collection=${to_collection}
27+
export PT_password=${PUPPET_FORGE_TOKEN}
28+
chmod u+x tasks/install_shell.sh
29+
tasks/install_shell.sh
30+
31+
echo "puppet $(/opt/puppetlabs/puppet/bin/puppet --version)"
32+
echo "facter $(/opt/puppetlabs/puppet/bin/facter --version)"
33+
/opt/puppetlabs/puppet/bin/puppet apply -e 'notice("puppet apply")'
34+
35+
# Make e.g. `puppet --version` work out of the box.
36+
PATH=/opt/puppetlabs/bin:$PATH \
37+
read -p "Explore the container? [y/N]: " choice && \
38+
choice=${choice:-N} && \
39+
if [ "${choice}" = "y" ]; then \
40+
bash; \
41+
else \
42+
echo "Moving on..."; \
43+
fi

docker/bin/install.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
# Usage: `./install.sh [<PLATFORM>] [<VERSION>]`
3+
#
4+
# Builds an upgrade process for the puppet-agent module and tags as
5+
# "pa-dev:<PLATFORM>".
6+
#
7+
# Parameters:
8+
# - PLATFORM: The platform on which the upgrade should occur. This also
9+
# supports comma-separated lists. Available:
10+
# - `amazon`
11+
# - `fedora`
12+
# - `rocky`
13+
# - `sles`
14+
# - `ubuntu`
15+
# Default: `ubuntu`
16+
# - BEFORE: The puppet-agent package version that is installed prior to upgrade.
17+
# Default: 7.34.0
18+
# - AFTER: The puppet-agent package version that should exist after upgrade.
19+
# Default: 8.1.0
20+
set -e
21+
22+
if [[ -z "${PUPPET_FORGE_TOKEN}" ]]; then
23+
echo "$0: Environment variable PUPPET_FORGE_TOKEN must be set"
24+
exit 1
25+
fi
26+
27+
cd "$(dirname "$0")/../.."
28+
platforms=${1:-rocky}
29+
version=${2:-8.11.0}
30+
for platform in ${platforms//,/ }
31+
do
32+
dockerfile='docker/install/dnf/Dockerfile'
33+
34+
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'
53+
;;
54+
55+
rocky*)
56+
base_image='rockylinux/rockylinux:9'
57+
;;
58+
59+
sles*)
60+
base_image='registry.suse.com/suse/sle15:15.6'
61+
dockerfile='docker/install/sles/Dockerfile'
62+
;;
63+
64+
*)
65+
echo "$0: Usage install.sh [amazon|fedora|rocky|sles]"
66+
exit 1
67+
;;
68+
esac
69+
70+
docker build --rm -f "${dockerfile}" . -t pa-dev:$platform.install \
71+
--build-arg BASE_IMAGE="${base_image}"
72+
docker run -e PUPPET_FORGE_TOKEN --rm -ti pa-dev:$platform.install "${version}"
73+
done
74+
echo Complete

docker/install/dnf/Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 rocky` 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+
# Dependencies resolved.
12+
# ========================================================================================================================================
13+
# Package Architecture Version Repository Size
14+
# ========================================================================================================================================
15+
# Installing:
16+
# puppet-agent x86_64 8.10.0-1.el8 puppet8 27 M
17+
18+
ARG BASE_IMAGE=rocky:8
19+
FROM ${BASE_IMAGE}
20+
21+
# Use this to force a cache reset (e.g. for output purposes)
22+
#COPY $0 /tmp/Dockerfile
23+
24+
# Install some other dependencies for ease of life.
25+
RUN dnf update -y \
26+
&& dnf install -y git \
27+
&& dnf clean all
28+
29+
# This is also duplicated in the docker/bin/helpers/run-upgrade.sh.
30+
ENV module_path=/tmp/modules
31+
WORKDIR "${module_path}/puppet_agent"
32+
COPY metadata.json ./
33+
34+
# Installing dependencies from source. These versions should be within the range
35+
# of `dependencies` in metadata.json.
36+
RUN git clone --depth 1 https://github.com/puppetlabs/puppetlabs-stdlib ../stdlib --branch v9.7.0
37+
RUN git clone --depth 1 https://github.com/puppetlabs/puppetlabs-inifile ../inifile --branch v6.2.0
38+
RUN git clone --depth 1 https://github.com/puppetlabs/puppetlabs-apt ../apt --branch v10.0.1
39+
RUN git clone --depth 1 https://github.com/puppetlabs/puppetlabs-facts ../facts --branch 1.7.0
40+
41+
# Now move the project directory's files into the image. That way, if these
42+
# files change, caching will skip everything before this.
43+
COPY docker/bin/helpers/run-install.sh /tmp/bin/run-install.sh
44+
COPY files/ ./files/
45+
COPY locales/ ./locales/
46+
COPY spec/ ./spec/
47+
COPY task_spec/ ./task_spec/
48+
COPY tasks/ ./tasks/
49+
COPY templates/ ./templates
50+
COPY types/ ./types/
51+
COPY Gemfile Gemfile.lock Rakefile ./
52+
COPY lib/ ./lib/
53+
COPY manifests/ ./manifests/
54+
55+
# Perform the install.
56+
ENTRYPOINT ["/tmp/bin/run-install.sh"]

docker/install/sles/Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 rocky` 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+
# (19/19) Installing: puppet-agent-8.11.0-1.sles15.x86_64 ..........................................................................[done]
13+
14+
ARG BASE_IMAGE=registry.suse.com/suse/sle15:15.6
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 zypper install --no-confirm wget git-core
22+
23+
# This is also duplicated in the docker/bin/helpers/run-upgrade.sh.
24+
ENV module_path=/tmp/modules
25+
WORKDIR "${module_path}/puppet_agent"
26+
COPY metadata.json ./
27+
28+
# Installing dependencies from source. These versions should be within the range
29+
# of `dependencies` in metadata.json.
30+
RUN git clone --depth 1 https://github.com/puppetlabs/puppetlabs-stdlib ../stdlib --branch v9.7.0
31+
RUN git clone --depth 1 https://github.com/puppetlabs/puppetlabs-inifile ../inifile --branch v6.2.0
32+
RUN git clone --depth 1 https://github.com/puppetlabs/puppetlabs-apt ../apt --branch v10.0.1
33+
RUN git clone --depth 1 https://github.com/puppetlabs/puppetlabs-facts ../facts --branch 1.7.0
34+
35+
# Now move the project directory's files into the image. That way, if these
36+
# files change, caching will skip everything before this.
37+
COPY docker/bin/helpers/run-install.sh /tmp/bin/run-install.sh
38+
COPY files/ ./files/
39+
COPY locales/ ./locales/
40+
COPY spec/ ./spec/
41+
COPY task_spec/ ./task_spec/
42+
COPY tasks/ ./tasks/
43+
COPY templates/ ./templates
44+
COPY types/ ./types/
45+
COPY Gemfile Gemfile.lock Rakefile ./
46+
COPY lib/ ./lib/
47+
COPY manifests/ ./manifests/
48+
49+
# Perform the install.
50+
ENTRYPOINT ["/tmp/bin/run-install.sh"]

tasks/install.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
"description": "The number of retries in case of network connectivity failures",
4242
"type": "Optional[Integer]",
4343
"default": 5
44+
},
45+
"username": {
46+
"description": "The username to use when downloading from a source location requiring authentication",
47+
"type": "Optional[String]"
48+
},
49+
"password": {
50+
"description": "The password to use when downloading from a source location requiring authentication",
51+
"type": "Optional[String]"
4452
}
4553
},
4654
"implementations": [

tasks/install_shell.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
"description": "The number of retries in case of network connectivity failures",
4444
"type": "Optional[Integer]",
4545
"default": 5
46+
},
47+
"username": {
48+
"description": "The username to use when downloading from a source location requiring authentication",
49+
"type": "Optional[String]"
50+
},
51+
"password": {
52+
"description": "The password to use when downloading from a source location requiring authentication",
53+
"type": "Optional[String]"
4654
}
4755
},
4856
"files": ["facts/tasks/bash.sh"],

tasks/install_shell.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ if [ -n "$PT_version" ]; then
100100
version=$PT_version
101101
fi
102102

103+
if [ -n "$PT_username" ]; then
104+
username=$PT_username
105+
else
106+
username='forge-key'
107+
fi
108+
109+
if [ -n "$PT_password" ]; then
110+
password=$PT_password
111+
fi
112+
103113
if [ -n "$PT_collection" ]; then
104114
# Check whether collection is nightly
105115
if [[ "$PT_collection" == *"nightly"* ]]; then
@@ -110,7 +120,7 @@ if [ -n "$PT_collection" ]; then
110120

111121
collection=$PT_collection
112122
else
113-
collection='puppet'
123+
collection='puppet8'
114124
fi
115125

116126
if [ -n "$PT_yum_source" ]; then
@@ -119,7 +129,11 @@ else
119129
if [ "$nightly" = true ]; then
120130
yum_source='https://artifactory.delivery.puppetlabs.net:443/artifactory/internal_nightly__local/yum'
121131
else
122-
yum_source='http://yum.puppet.com'
132+
yum_source='https://yum-puppetcore.puppet.com/public'
133+
if [ -z "$password" ]; then
134+
echo "A password parameter is required to install from ${yum_source}"
135+
exit 1
136+
fi
123137
fi
124138
fi
125139

@@ -583,6 +597,12 @@ install_file() {
583597
fi
584598

585599
rpm -Uvh --oldpackage --replacepkgs "$2"
600+
if [[ -n $username ]]; then
601+
sed -i "s/^#\?username=.*/username=${username}/" "/etc/yum.repos.d/${collection}-release.repo"
602+
fi
603+
if [[ -n $password ]]; then
604+
sed -i "s/^#\?password=.*/password=${password}/" "/etc/yum.repos.d/${collection}-release.repo"
605+
fi
586606
exists dnf && PKGCMD=dnf || PKGCMD=yum
587607
if test "$version" = 'latest'; then
588608
run_cmd "${PKGCMD} install -y puppet-agent && ${PKGCMD} upgrade -y puppet-agent"
@@ -607,6 +627,12 @@ install_file() {
607627
fi
608628

609629
run_cmd "zypper install --no-confirm '$2'"
630+
if [[ -n $username ]]; then
631+
sed -i "s/^username=.*/username=${username}/" "/etc/zypp/credentials.d/PuppetcoreCreds"
632+
fi
633+
if [[ -n $password ]]; then
634+
sed -i "s/^password=.*/password=${password}/" "/etc/zypp/credentials.d/PuppetcoreCreds"
635+
fi
610636
if test "$version" = "latest"; then
611637
run_cmd "zypper install --no-confirm 'puppet-agent'"
612638
else
@@ -669,9 +695,9 @@ case $platform in
669695
info "SLES platform! Lets get you an RPM..."
670696

671697
if [[ $PT__noop != true ]]; then
672-
for key in "puppet" "puppet-20250406"; do
698+
for key in "puppet-20250406"; do
673699
gpg_key="${tmp_dir}/RPM-GPG-KEY-${key}"
674-
do_download "https://yum.puppet.com/RPM-GPG-KEY-${key}" "$gpg_key"
700+
do_download "https://yum-puppetcore.puppet.com/public/RPM-GPG-KEY-${key}" "$gpg_key"
675701
rpm --import "$gpg_key"
676702
rm -f "$gpg_key"
677703
done

0 commit comments

Comments
 (0)