First modules#
As described in the module reference modules are used as libraries or shared building blocks across images.
To add a module, the image.yaml
file must be modified to add a modules section. This is responsible for defining module repositories and providing the list of modules to be installed in order. Modules may come from the local file system or from remote git based repositories e.g. on github.
Edit the file to add the highlighted section below.
name: my-example
version: 1.0
from: centos:7
description: My Example Image
modules:
repositories:
- path: modules
As per the below diagram a number of directories must be created next to image.yaml
.
Once the modules subdirectory and the respective module directories below that have been created they can be added to the image. In order to select a module component from a repository it is necessary to add an install
section as per the highlighted section below.
modules:
repositories:
- path: modules
# Install selected modules (in order)
install:
- name: jdk8
- name: user
- name: tomcat
In order to add and populate the local file system modules follow the below instructions.
Note
All module yaml files should be named module.yaml
JDK8#
Create an empty
module.yaml
file within thejdk8
directory.Enter the following code:
schema_version: 1
name: jdk8
version: 1.0
description: Module installing OpenJDK 8
envs:
- name: "JAVA_HOME"
value: "/usr/lib/jvm/java-1.8.0-openjdk"
packages:
install:
- java-1.8.0-openjdk-devel
An environment variable has been defined that will be present in the container after running the image.
packages have been used to add the JDK RPM.
User#
Create the
module.yaml
andcreate.sh
files within theuser
directory.Enter the following code:
schema_version: 1
name: user
version: 1.0
description: "Creates a regular user that could be used to run any service, gui/uid: 1000"
execute:
- script: create.sh
run:
user: 1000
workdir: "/home/user"
#!/bin/sh
set -e
groupadd -r user -g 1000 && useradd -u 1000 -r -g user -m -d /home/user -s /sbin/nologin -c "Regular user" user
Tomcat#
Finally, create the following two files inside the
tomcat
directory:
#!/bin/sh
set -e
tar -C /home/user -xf /tmp/artifacts/tomcat.tar.gz
chown user:user -R /home/user
name: tomcat
version: 1.0
description: "Module used to install Tomcat 8"
# Defined artifacts that are used to build the image
artifacts:
- name: tomcat.tar.gz
url: https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz
md5: 080075877a66adf52b7f6d0013fa9730
execute:
- script: install.sh
run:
cmd:
- "/home/user/apache-tomcat-8.5.24/bin/catalina.sh"
- "run"
The artifact command is used to retrieve external artifacts that need to be added to the image.
Move onto the build section to build this new image.