Skip to content

Commit 95ccc9d

Browse files
committed
Move config files into the container
This is an experiment to move configuration files into the container and only replace environment variables. It creates a file to start the container where it creates all the needed files based on templates and environment variables. If the file already exists, it won't be overwritten. This allows bypassing the template.
1 parent c7b91a3 commit 95ccc9d

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

container-images/candlepin/Containerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@ FROM quay.io/centos/centos:stream9
22
RUN dnf -y update && \
33
dnf clean all
44
RUN dnf -y --nodocs --setopt install_weak_deps=False install \
5+
gettext \
56
https://yum.theforeman.org/candlepin/4.4/el9/x86_64/candlepin-4.4.14-1.el9.noarch.rpm \
67
https://yum.theforeman.org/candlepin/4.4/el9/x86_64/candlepin-selinux-4.4.14-1.el9.noarch.rpm && \
78
dnf clean all
89

9-
CMD ["/usr/libexec/tomcat/server", "start"]
10+
ENV CANDLEPIN_KEYSTORE_PATH=/etc/candlepin/certs/truststore
11+
ENV CANDLEPIN_KEYSTORE_PASSWORD=
12+
ENV CANDLEPIN_TRUSTSTORE_PATH=/etc/candlepin/certs/truststore
13+
# Optional - if unset, CANDLEPIN_KEYSTORE_PASSWORD is used
14+
ENV CANDLEPIN_TRUSTSTORE_PASSWORD=
15+
16+
ADD broker.xml.tpl /etc/candlepin/
17+
18+
ADD start /usr/libexec/candlepin/
19+
20+
CMD ["/usr/libexec/candlepin/start"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Environment variables
2+
3+
All environment variables are defined in `Containerfile`.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<acceptors>
1212
<acceptor name="in-vm">vm://0</acceptor>
13-
<acceptor name="stomp">tcp://localhost:61613?protocols=STOMP;useEpoll=false;sslEnabled=true;trustStorePath=/etc/candlepin/certs/truststore;trustStorePassword={{ candlepin_keystore_password }};keyStorePath=/etc/candlepin/certs/keystore;keyStorePassword={{ candlepin_keystore_password }};needClientAuth=true</acceptor>
13+
<acceptor name="stomp">tcp://localhost:61613?protocols=STOMP;useEpoll=false;sslEnabled=true;trustStorePath=${CANDLEPIN_TRUSTSTORE_PATH};trustStorePassword=${CANDLEPIN_TRUSTSTORE_PASSWORD};keyStorePath=${CANDLEPIN_KEYSTORE_PATH};keyStorePassword=${CANDLEPIN_KEYSTORE_PASSWORD};needClientAuth=true</acceptor>
1414
</acceptors>
1515

1616
<security-enabled>true</security-enabled>

container-images/candlepin/start

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ -z $CANDLEPIN_TRUSTSTORE_PASSWORD ]] ; then
6+
CANDLEPIN_TRUSTSTORE_PASSWORD=$CANDLEPIN_KEYSTORE_PASSWORD
7+
export CANDLEPIN_TRUSTSTORE_PASSWORD
8+
fi
9+
10+
for template in /etc/candlepin/*.tpl ; do
11+
destination=${template%%.tpl}
12+
if [[ ! -f "$destination" ]] ; then
13+
envsubst < "$template" > "$destination"
14+
fi
15+
done
16+
17+
exec /usr/libexec/tomcat/server start

roles/candlepin/tasks/artemis.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
ansible.builtin.set_fact:
99
candlepin_artemis_client_dn: "{{ openssl_response.stdout | replace('subject=', '') }}"
1010

11-
- name: Create Candlepin broker.xml
11+
- name: Create Candlepin keystore password secret
1212
containers.podman.podman_secret:
1313
state: present
14-
name: candlepin-artemis-broker-xml
15-
data: "{{ lookup('ansible.builtin.template', 'broker.xml.j2') }}"
16-
labels:
17-
filename: broker.xml
18-
app: artemis
14+
name: candlepin-keystore-password
15+
data: "{{ candlepin_keystore_password }}"
1916

2017
- name: Create Tomcat login config
2118
containers.podman.podman_secret:

roles/candlepin/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
- 'candlepin-tomcat-keystore,target=/etc/candlepin/certs/keystore,mode=0440,type=mount'
6464
- 'candlepin-tomcat-truststore,target=/etc/candlepin/certs/truststore,mode=0440,type=mount'
6565
- 'candlepin-candlepin-conf,target=/etc/candlepin/candlepin.conf,mode=0440,type=mount'
66-
- 'candlepin-artemis-broker-xml,target=/etc/candlepin/broker.xml,mode=440,type=mount'
66+
- 'candlepin-keystore-password,target=CANDLEPIN_KEYSTORE_PASSWORD,type=env'
6767
- 'candlepin-tomcat-server-xml,target=/etc/tomcat/server.xml,mode=440,type=mount'
6868
- 'candlepin-tomcat-conf,target=/etc/tomcat/tomcat.conf,mode=440,type=mount'
6969
- 'candlepin-artemis-login-config,target=/etc/tomcat/login.config,mode=440,type=mount'

0 commit comments

Comments
 (0)