Skip to content

Commit db51958

Browse files
authored
Merge pull request #2 from CSHieuV/consistency-fixes
Update to Bootstrap Container
2 parents 38c7a76 + e91c5cd commit db51958

File tree

4 files changed

+50
-33
lines changed

4 files changed

+50
-33
lines changed

Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
FROM amazonlinux:2023
1+
FROM public.ecr.aws/amazonlinux/amazonlinux:2023
22

33
# Install necessary packages
4-
RUN yum update -y && \
5-
yum install -y \
4+
RUN yum update -y
5+
6+
RUN yum install -y \
67
aws-cli \
78
jq \
89
util-linux \
910
e2fsprogs \
1011
xfsprogs \
1112
lvm2 \
1213
mdadm && \
13-
yum clean all && \
14-
# Verify that all packages are installed
14+
yum clean all
15+
16+
# Verify that all packages are installed
17+
RUN \
1518
command -v aws && \
1619
command -v jq && \
1720
command -v lsblk && \
@@ -23,8 +26,5 @@ RUN yum update -y && \
2326
# Copy the wrapper script into the container
2427
COPY bootstrap-script.sh /usr/local/bin/bootstrap-script.sh
2528

26-
# Make the wrapper script executable
27-
RUN chmod +x /usr/local/bin/bootstrap-script.sh
28-
2929
# Set the wrapper script as the entry point
3030
ENTRYPOINT ["/usr/local/bin/bootstrap-script.sh"]

Makefile

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1-
IMAGE_NAME = bottlerocket-bootstrap-container:latest
1+
# IMAGE_NAME is the full name of the container image being built.
2+
IMAGE_NAME ?= $(notdir $(shell pwd -P))$(IMAGE_ARCH_SUFFIX):$(IMAGE_VERSION)$(addprefix -,$(SHORT_SHA))
3+
# IMAGE_VERSION is the semver version that's tagged on the image.
4+
IMAGE_VERSION = $(shell cat VERSION)
5+
# SHORT_SHA is the revision that the container image was built with.
6+
SHORT_SHA ?= $(shell git describe --abbrev=8 --always --dirty='-dev' --exclude '*' || echo "unknown")
7+
# IMAGE_ARCH_SUFFIX is the runtime architecture designator for the container
8+
# image, it is appended to the IMAGE_NAME unless the name is specified.
9+
IMAGE_ARCH_SUFFIX ?= $(addprefix -,$(ARCH))
10+
# DESTDIR is where the release artifacts will be written.
11+
DESTDIR ?= .
12+
# DISTFILE is the path to the dist target's output file - the container image
13+
# tarball.
14+
DISTFILE ?= $(subst /,,$(DESTDIR))/$(subst /,_,$(IMAGE_NAME)).tar.gz
215

3-
.PHONY: all build clean
16+
UNAME_ARCH = $(shell uname -m)
17+
ARCH ?= $(lastword $(subst :, ,$(filter $(UNAME_ARCH):%,x86_64:amd64 aarch64:arm64)))
418

5-
# Run all build tasks for this container image
6-
all: build_amd64 build_arm64
19+
.PHONY: all build dist clean
720

8-
# Build the container image for the amd64 architecture
9-
build_amd64:
10-
docker build --tag $(IMAGE_NAME)-amd64 -f Dockerfile .
21+
# Run all build tasks for this container image.
22+
all: build
1123

12-
# Build the container image for the arm64 architecture
13-
build_arm64:
14-
docker build --tag $(IMAGE_NAME)-arm64 -f Dockerfile .
24+
# Create a distribution container image tarball for release.
25+
dist: all
26+
@mkdir -p $(dir $(DISTFILE))
27+
docker save $(IMAGE_NAME) | gzip > $(DISTFILE)
28+
29+
# Build the container image.
30+
build:
31+
DOCKER_BUILDKIT=1 docker build $(DOCKER_BUILD_FLAGS) \
32+
--tag $(IMAGE_NAME) \
33+
--build-arg IMAGE_VERSION="$(IMAGE_VERSION)" \
34+
-f Dockerfile . >&2
1535

16-
# Clean up the build artifacts (if there are any to clean)
1736
clean:
18-
rm -f $(IMAGE_NAME)
37+
rm -f $(DISTFILE)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Bottlerocket Control Container
1+
# Bottlerocket Bootstrap Container
22

3-
This is the bootstrap container for the [Bottlerocket](https://github.com/bottlerocket-os/bottlerocket) operating system. This container
4-
image allows the user to provide their own script to run bootstrap commands to setup their own configuration during runtime.
3+
This is the bootstrap container for the [Bottlerocket](https://github.com/bottlerocket-os/bottlerocket) operating system.
4+
This container image allows the user to provide their own script to run bootstrap commands to setup their own configuration during runtime.
55

66
## Using the Container Image
77

bootstrap-script.sh

100644100755
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
#!/usr/bin/env bash
22

3-
set -euo pipefail
4-
set -x
3+
set -xeuo pipefail
54

65
# Full path to the base64-encoded user data
7-
USER_DATA_PATH=/.bottlerocket/bootstrap-containers/current/user-data
6+
USER_DATA_PATH='/.bottlerocket/bootstrap-containers/current/user-data'
87

98
# If the user data file is there, not empty, and not a directory, make it executable
10-
if [ -s "$USER_DATA_PATH" ] && [ ! -d "$USER_DATA_PATH" ]; then
11-
chmod +x "$USER_DATA_PATH"
9+
if [[ -s "${USER_DATA_PATH}" ]] && [[ ! -d "${USER_DATA_PATH}" ]]; then
10+
chmod +x "${USER_DATA_PATH}"
1211

1312
# If the decoded script is there and executable, then execute it.
14-
if [ -x "$USER_DATA_PATH" ]; then
15-
echo "Executing user bootstrap script: $USER_DATA_PATH"
16-
exec "$USER_DATA_PATH"
13+
if [ -x "${USER_DATA_PATH}" ]; then
14+
exec "${USER_DATA_PATH}"
1715
else
18-
echo "Warning: User bootstrap script not found or not executable: $USER_DATA_PATH"
16+
echo "ERROR: User bootstrap script not found or not executable: ${USER_DATA_PATH}" >&2
1917
exit 1
2018
fi
2119
else
22-
echo "Warning: User data not found or is a directory: $USER_DATA_PATH"
20+
echo "ERROR: User data not found or is a directory: ${USER_DATA_PATH}" >&2
2321
exit 1
2422
fi

0 commit comments

Comments
 (0)