Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add Dockerfile for controller, build with bottlerocket-sdk #85

Merged
merged 2 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
334 changes: 150 additions & 184 deletions Cargo.lock

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions Dockerfile.sdk_openssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ARG ARCH
FROM public.ecr.aws/bottlerocket/bottlerocket-sdk-${ARCH}:v0.22.0 as build
ARG ARCH
ARG OPENSSL_VERSION=1.1.1k
ARG OPENSSL_SHA256SUM=892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5
USER root

# Build openssl using musl toolchain for openssl-sys crate
RUN dnf install -y perl
RUN mkdir /musl && \
echo "/musl/lib" >> /etc/ld-musl-${ARCH}.path && \
ln -s /usr/include/${ARCH}-linux-gnu/asm /${ARCH}-bottlerocket-linux-musl/sys-root/usr/include/asm && \
ln -s /usr/include/asm-generic /${ARCH}-bottlerocket-linux-musl/sys-root/usr/include/asm-generic && \
ln -s /usr/include/linux /${ARCH}-bottlerocket-linux-musl/sys-root/usr/include/linux

RUN curl -O -sSL https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz && \
echo "${OPENSSL_SHA256SUM} openssl-${OPENSSL_VERSION}.tar.gz" | sha256sum --check && \
tar -xzf openssl-${OPENSSL_VERSION}.tar.gz && \
cd openssl-${OPENSSL_VERSION} && \
./Configure no-shared no-async -fPIC --prefix=/musl --openssldir=/musl/ssl linux-${ARCH} && \
env C_INCLUDE_PATH=/musl/include/ make depend 2> /dev/null && \
make -j && \
make install && \
cd .. && rm -rf openssl-${OPENSSL_VERSION}

# We need these environment variables set for building the `openssl-sys` crate
ENV PKG_CONFIG_ALLOW_CROSS=1
ENV OPENSSL_STATIC=true
ENV OPENSSL_DIR=/musl
Comment on lines +27 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Shouldn't ENVs be closer to ARGs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's absolutely necessary since it's not used for building openssl. These are environment variables we should set after we're able to successfully build openssl with musl. It's intended for building the openssl-sys crate later when we build the controller image. I'll add a comment here to indicate what these environment variables are for.

29 changes: 23 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
.PHONY: example-test-agent-container
.PHONY: sdk-openssl example-test-agent-image controller-image images

# Build a container image for daemon and tools.
example-test-agent-container:
docker build \
--network=host \
--tag 'example_test_agent' \
ARCH=$(shell uname -m)

images: controller-image

# Augment the bottlerocket-sdk image with openssl built with the musl toolchain
sdk-openssl:
webern marked this conversation as resolved.
Show resolved Hide resolved
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(ARCH)" \
--tag "bottlerocket-sdk-openssl-$(ARCH)" \
-f Dockerfile.sdk_openssl .

# Build the container image for the example test-agent program
example-test-agent-image: sdk-openssl
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(ARCH)" \
--tag "example-testsys-agent" \
-f test-agent/examples/example_test_agent/Dockerfile .

controller-image: sdk-openssl
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(ARCH)" \
--tag "testsys-controller" \
-f controller/Dockerfile .
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false
[dependencies]
# k8s-openapi must match the version required by kube and enable a k8s version feature
k8s-openapi = { version = "0.13.0", default-features = false, features = ["v1_20"] }
kube = { version = "0.59.0", default-features = false, features = ["client", "derive", "rustls-tls"] }
kube = { version = "0.59.0", default-features = true, features = [ "derive"] }
log = "0.4"
schemars = "0.8"
serde = { version = "1", features = [ "derive" ] }
Expand Down
2 changes: 1 addition & 1 deletion controller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env_logger = "0.9"
futures = "0.3"
# k8s-openapi must match the version required by kube and enable a k8s version feature
k8s-openapi = { version = "0.13.0", default-features = false, features = ["v1_20"] }
kube = { version = "0.59.0", default-features = false, features = ["client", "derive", "rustls-tls"] }
kube = { version = "0.59.0", default-features = true, features = [ "derive"] }
kube-runtime = "0.59.0"
log = "0.4"
schemars = "0.8"
Expand Down
16 changes: 16 additions & 0 deletions controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG ARCH
FROM bottlerocket-sdk-openssl-${ARCH} as build
ARG ARCH
USER root

ADD ./ /src/
WORKDIR /src/controller
RUN cargo install --locked --target ${ARCH}-bottlerocket-linux-musl --path . --root ./

FROM scratch
# Copy CA certificates store
COPY --from=public.ecr.aws/amazonlinux/amazonlinux:2 /etc/ssl /etc/ssl
COPY --from=public.ecr.aws/amazonlinux/amazonlinux:2 /etc/pki /etc/pki
COPY --from=build /src/controller/bin/controller ./

ENTRYPOINT ["./controller"]
19 changes: 14 additions & 5 deletions test-agent/examples/example_test_agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# TODO Use Bottlerocket SDK
FROM rust:1.53.0
WORKDIR /src
ARG ARCH
FROM bottlerocket-sdk-openssl-${ARCH} as build
ARG ARCH
USER root

ADD ./ /src/
WORKDIR /src/test-agent
RUN cargo install --path . --example example_test_agent --root ./
ENTRYPOINT ["/src/test-agent/bin/example_test_agent"]
RUN cargo install --locked --target ${ARCH}-bottlerocket-linux-musl --path . --example example_test_agent --root ./

FROM scratch
# Copy CA certificates store
COPY --from=public.ecr.aws/amazonlinux/amazonlinux:2 /etc/ssl /etc/ssl
COPY --from=public.ecr.aws/amazonlinux/amazonlinux:2 /etc/pki /etc/pki
COPY --from=build /src/test-agent/bin/example_test_agent ./

ENTRYPOINT ["./example_test_agent"]
2 changes: 1 addition & 1 deletion yamlgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ publish = false

[build-dependencies]
client = { path = "../client" }
kube = { version = "0.59.0", default-features = false, features = ["client", "rustls-tls"] }
kube = { version = "0.59.0", default-features = true, features = [ "derive"] }
serde_yaml = "0.8"