Skip to content

Commit 375a22b

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 1e102b5 commit 375a22b

File tree

7 files changed

+294
-15
lines changed

7 files changed

+294
-15
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=puppetcore7
15+
;;
16+
8)
17+
to_collection=puppetcore8
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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"collection": {
99
"description": "The Puppet collection to install from (defaults to puppet, which maps to the latest collection released)",
10-
"type": "Optional[Enum[puppet7, puppet8, puppet, puppet7-nightly, puppet8-nightly, puppet-nightly]]"
10+
"type": "Optional[Enum[puppet7, puppet8, puppet, puppet7-nightly, puppet8-nightly, puppet-nightly, puppetcore7, puppetcore8]]"
1111
},
1212
"absolute_source": {
1313
"description": "The absolute source location to find the Puppet agent package",
@@ -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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"collection": {
1111
"description": "The Puppet collection to install from (defaults to puppet, which maps to the latest collection released)",
12-
"type": "Optional[Enum[puppet7, puppet8, puppet, puppet7-nightly, puppet8-nightly, puppet-nightly]]"
12+
"type": "Optional[Enum[puppet7, puppet8, puppet, puppet7-nightly, puppet8-nightly, puppet-nightly, puppetcore7, puppetcore8]]"
1313
},
1414
"absolute_source": {
1515
"description": "The absolute source location to find the Puppet agent package",
@@ -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: 53 additions & 13 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
@@ -116,10 +126,18 @@ fi
116126
if [ -n "$PT_yum_source" ]; then
117127
yum_source=$PT_yum_source
118128
else
119-
if [ "$nightly" = true ]; then
120-
yum_source='http://nightlies.puppet.com/yum'
129+
if [[ "$collection" == "puppetcore"* ]]; then
130+
yum_source='https://yum-puppetcore.puppet.com/public'
131+
if [ -z "$password" ]; then
132+
echo "A password parameter is required to install from ${yum_source}"
133+
exit 1
134+
fi
121135
else
122-
yum_source='http://yum.puppet.com'
136+
if [ "$nightly" = true ]; then
137+
yum_source='http://nightlies.puppet.com/yum'
138+
else
139+
yum_source='http://yum.puppet.com'
140+
fi
123141
fi
124142
fi
125143

@@ -582,7 +600,14 @@ install_file() {
582600
fi
583601
fi
584602

603+
repo="/etc/yum.repos.d/${collection/core/}-release.repo"
585604
rpm -Uvh --oldpackage --replacepkgs "$2"
605+
if [[ -n $username ]]; then
606+
sed -i "s/^#\?username=.*/username=${username}/" "${repo}"
607+
fi
608+
if [[ -n $password ]]; then
609+
sed -i "s/^#\?password=.*/password=${password}/" "${repo}"
610+
fi
586611
exists dnf && PKGCMD=dnf || PKGCMD=yum
587612
if test "$version" = 'latest'; then
588613
run_cmd "${PKGCMD} install -y puppet-agent && ${PKGCMD} upgrade -y puppet-agent"
@@ -607,6 +632,12 @@ install_file() {
607632
fi
608633

609634
run_cmd "zypper install --no-confirm '$2'"
635+
if [[ -n $username ]]; then
636+
sed -i "s/^username=.*/username=${username}/" "/etc/zypp/credentials.d/PuppetcoreCreds"
637+
fi
638+
if [[ -n $password ]]; then
639+
sed -i "s/^password=.*/password=${password}/" "/etc/zypp/credentials.d/PuppetcoreCreds"
640+
fi
610641
if test "$version" = "latest"; then
611642
run_cmd "zypper install --no-confirm 'puppet-agent'"
612643
else
@@ -669,22 +700,31 @@ case $platform in
669700
info "SLES platform! Lets get you an RPM..."
670701

671702
if [[ $PT__noop != true ]]; then
672-
for key in "puppet" "puppet-20250406"; do
673-
gpg_key="${tmp_dir}/RPM-GPG-KEY-${key}"
674-
do_download "https://yum.puppet.com/RPM-GPG-KEY-${key}" "$gpg_key"
675-
rpm --import "$gpg_key"
676-
rm -f "$gpg_key"
677-
done
703+
if [[ "$PT_collection" =~ core ]]; then
704+
for key in "puppet"; do
705+
gpg_key="${tmp_dir}/RPM-GPG-KEY-${key}"
706+
do_download "https://yum-puppetcore.puppet.com/public/RPM-GPG-KEY-${key}" "$gpg_key"
707+
rpm --import "$gpg_key"
708+
rm -f "$gpg_key"
709+
done
710+
else
711+
for key in "puppet" "puppet-20250406"; do
712+
gpg_key="${tmp_dir}/RPM-GPG-KEY-${key}"
713+
do_download "https://yum.puppet.com/public/RPM-GPG-KEY-${key}" "$gpg_key"
714+
rpm --import "$gpg_key"
715+
rm -f "$gpg_key"
716+
done
717+
fi
678718
fi
679719

680720
filetype="noarch.rpm"
681-
filename="${collection}-release-sles-${platform_version}.noarch.rpm"
721+
filename="${collection/core/}-release-sles-${platform_version}.noarch.rpm"
682722
download_url="${yum_source}/${filename}"
683723
;;
684724
"el")
685725
info "Red hat like platform! Lets get you an RPM..."
686726
filetype="rpm"
687-
filename="${collection}-release-el-${platform_version}.noarch.rpm"
727+
filename="${collection/core/}-release-el-${platform_version}.noarch.rpm"
688728
download_url="${yum_source}/${filename}"
689729
;;
690730
"Amzn"|"Amazon Linux")
@@ -698,13 +738,13 @@ case $platform in
698738
elif (( platform_version == 2 || platform_version >= 2023 )); then
699739
platform_package="amazon"
700740
fi
701-
filename="${collection}-release-${platform_package}-${platform_version}.noarch.rpm"
741+
filename="${collection/core/}-release-${platform_package}-${platform_version}.noarch.rpm"
702742
download_url="${yum_source}/${filename}"
703743
;;
704744
"Fedora")
705745
info "Fedora platform! Lets get the RPM..."
706746
filetype="rpm"
707-
filename="${collection}-release-fedora-${platform_version}.noarch.rpm"
747+
filename="${collection/core/}-release-fedora-${platform_version}.noarch.rpm"
708748
download_url="${yum_source}/${filename}"
709749
;;
710750
"Debian")

0 commit comments

Comments
 (0)