Build Base and Third-Party Images
This page describes how to build the Self-Managed Commerce base and third-party images using the build tools included in the Self-Managed Commerce ep-commerce Git project.
note
For information about containerized Self-Managed Commerce, see Containerized Environments.
Prerequisites
Before you begin, ensure you meet the following prerequisites.
Build Environment Requirements
The image build tools are designed to be run in an suitably configured environment. For more information, see Configure the Build Environment.
Ansible Playbook build_base_images.yml
Use the included devops/build_tools/build_base_images.yml playbook to build the base images and third-party images.
Basic Usage
- Establish a shell session on the build host.
- Clone the Self-Managed Commerce source code project
ep-commercefrom your organization Git repository. - Checkout the
ep-commercebranch that you want to build. - Change directory to
devops/build_tools. - Invoke the playbook to build the base and third-party images.
ansible-playbook build_base_images.yml
Output
The playbook will output container images and a file with details about the container images.
Container images
The playbook outputs the four container images described below.
| Image Name | Description | Default Image Tag |
|---|---|---|
ep/amazonlinux_java | Java base-image, built on an Amazon Linux 2023 base image. The build tools use the Java version specified in the (ops-spec.json file). | <java_version> |
ep/tomcat | Tomcat base image. The build tools use the Tomcat version specified in the (ops-spec.json file). | <tomcat_version>-<java_version> |
ep/activemq | ActiveMQ application image. The build tools use the ActiveMQ version specified in the (ops-spec.json file). | <activemq_version> |
ep/mysql | MySQL application image. The build tools use the containerized MySQL version specified in the (ops-spec.json file). | <mysql_version> |
tip
For information about the relationship between the Self-Managed Commerce application images, the base images, and the deployment package, see Self-Managed Commerce Deployment Artifacts.
Image Facts File
The playbook outputs a text file that lists the names and tags of created images. The default location of the file is /opt/env/image_facts.env. Read or source this file to determine the fully-qualified name and tag of each image that has been built. The values in this file can be used to perform additional operations, such as pushing the images to a remote image repository.
The following key-value pairs can be found in the image facts file in the format of shell variables.
| Key name | Default Value |
|---|---|
IMAGE_ACTIVEMQ_FQN | ep/activemq:<activemq_version> |
IMAGE_AMAZONLINUX_JAVA_FQN | ep/amazonlinux-java:<java_version> |
IMAGE_MYSQL_FQN | ep/mysql:<mysql_version> |
IMAGE_TOMCAT_FQN | ep/tomcat:<tomcat_version>-<java_version> |
Using the Image Facts File
Use the image facts file by loading it in your current shell using the source command, then use the values to perform additional operations such as pushing the images.
Example:
source /opt/env/image_facts.env
docker push "${IMAGE_ACTIVEMQ_FQN}" # or img push "${IMAGE_ACTIVEMQ_FQN}"
docker push "${IMAGE_AMAZONLINUX_JAVA_FQN}" # or img push "${IMAGE_AMAZONLINUX_JAVA_FQN}"
docker push "${IMAGE_MYSQL_FQN}" # or img push "${IMAGE_MYSQL_FQN}"
docker push "${IMAGE_TOMCAT_FQN}" # or img push "${IMAGE_TOMCAT_FQN}"
Playbook options
Additional options are available that allow you to control the behaviour and output of the playbook.
Building without a Docker daemon
The Ansible playbook and roles support building container images in a daemonless environment by using the the img tool instead of docker. The img tool is installed when you configure your environment with the steps described in Configure a Build Host or Configure a Build Image.
note
The img command requires that the USER environment variable be set. We have observed that the USER variable is not set when accessing Linux host using AWS Session Manager. You may need to set the USER environment variable manually before building images with the img command. An example of how to do that is:
export USER=$(id -un)
To use img for daemonless container image builds, set the Ansible variable use_img to true. You can set this on the command line with the -e use_img='true' syntax when you run the playbook, as shown in the below example:
ansible-playbook -e use_img='true' build_base_images.yml
To learn more about the img tool, see the img repository on GitHub.
Building the images separately
Under some circumstances you might want to build the Self-Managed Commerce base and third-party images individually.
note
The tomcat and activemq images require that the amazonlinux_java image has already been built.
- Establish a shell session on the build host.
- Clone the Self-Managed Commerce source code project
ep-commercefrom your organization Git repository. - Checkout the
ep-commercebranch that you want to build. - Change directory to
devops/build_tools. - Invoke
ansible-playbook build_base_images.yml -t amazonlinux-javato build the Amazon Linux Java image. - Invoke
ansible-playbook build_base_images.yml -t tomcatto build the Tomcat image, based on the Amazon Linux Java image. - Invoke
ansible-playbook build_base_images.yml -t activemqto to build the ActiveMQ image, based on the Amazon Linux Java image. - Invoke
ansible-playbook build_base_images.yml -t mysqlto build the MySQL image.
Specifying an image name prefix
All image names include a prefix value, which can be customized at playbook runtime. If you will be pushing images to a remote repository, this variable can be customized to include the repository URL.
| Variable Name | Default Value |
|---|---|
image_name_prefix | ep |
Example:
ansible-playbook -e image_name_prefix='1234567.dkr.ecr.us-west-2.amazonaws.com/ep' build_base_images.yml
Image Tag
The image tags can be customized using variables at playbook runtime.
note
By default, the image tags are determined by version strings defined in the Operations Specification (ops-spec.json) file. For more information on the format and contents of this file, see Operations Specification (ops-spec.json).
| Variable Name | Default Value |
|---|---|
image_tag_java | Java version defined in ops-spec.json |
image_tag_tomcat | Application server version defined in ops-spec.json |
image_tag_activemq | ActiveMQ version defined in ops-spec.json |
image_tag_mysql | MySQL container version defined in ops-spec.json |
Example:
ansible-playbook -e image_tag_activemq='dev' build_base_images.yml
Change the path of the image facts file
The path to the image facts file can be changed by setting the image_facts_file variable when running ansible-playbook.
Example:
ansible-playbook -e image_facts_file='/tmp/image_facts.env' build_base_images.yml