From ffce43172716ee2c0efe0169c5865b67d77231da Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Sun, 11 Sep 2022 23:18:42 -0700 Subject: [PATCH] Add debug image. --- BUILDING.md | 3 +++ Cargo.lock | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + Dockerfile.debug | 46 ++++++++++++++++++++++++++++++++++++++ README.md | 6 +++++ src/main.rs | 2 ++ 6 files changed, 116 insertions(+) create mode 100644 Dockerfile.debug diff --git a/BUILDING.md b/BUILDING.md index 63ef7bb..1522287 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -8,6 +8,9 @@ docker buildx build --pull --push --progress plain --platform linux/arm64,linux/ # If the new version is stable then update latest: docker buildx build --pull --push --progress plain --platform linux/arm64,linux/amd64 -t public.ecr.aws/stefansundin/bottlerocket-bootstrap-associate-eip:latest . + +# Build the debug image: +docker buildx build --pull --push --progress plain --platform linux/arm64,linux/amd64 -t public.ecr.aws/stefansundin/bottlerocket-bootstrap-associate-eip:debug -f Dockerfile.debug . ``` If the build crashes then it is most likely because Docker ran out of memory. Increase the amount of RAM allocated to Docker and quit other programs during the build. diff --git a/Cargo.lock b/Cargo.lock index 564910d..68cb810 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,17 @@ dependencies = [ "memchr", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -321,6 +332,7 @@ version = "0.1.0" dependencies = [ "aws-config", "aws-sdk-ec2", + "env_logger", "tokio", ] @@ -389,6 +401,19 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "env_logger" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "fastrand" version = "1.8.0" @@ -490,6 +515,15 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hex" version = "0.4.3" @@ -530,6 +564,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.20" @@ -897,6 +937,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + [[package]] name = "time" version = "0.3.14" @@ -1163,6 +1212,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 6ca883b..2e0a0fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" [dependencies] aws-config = "0.48.0" aws-sdk-ec2 = "0.18.0" +env_logger = "0.9.0" tokio = { version = "1", features = ["macros"] } diff --git a/Dockerfile.debug b/Dockerfile.debug new file mode 100644 index 0000000..1e9979e --- /dev/null +++ b/Dockerfile.debug @@ -0,0 +1,46 @@ +# This image has more logging enabled and the binary is not stripped. +# https://docs.aws.amazon.com/sdk-for-rust/latest/dg/logging.html + +FROM rust:1-bullseye AS builder + +ARG TARGETARCH + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y musl-tools + +WORKDIR /src + +ENV CC=musl-gcc +ENV AR=ar +ENV RUST_BACKTRACE=full + +ADD . . + +RUN rustup --version + +RUN case "$TARGETARCH" in \ + arm64) TARGET=aarch64-unknown-linux-musl ;; \ + amd64) TARGET=x86_64-unknown-linux-musl ;; \ + *) echo "Does not support $TARGETARCH" && exit 1 ;; \ + esac && \ + rustup target add $TARGET && \ + cargo build --release --target $TARGET && \ + mv target/$TARGET/release/bottlerocket-bootstrap-associate-eip target/release/ + +# Copy the binary into an empty docker image +FROM scratch + +LABEL org.opencontainers.image.authors="Stefan Sundin" +LABEL org.opencontainers.image.url="https://github.com/stefansundin/bottlerocket-bootstrap-associate-eip" + +COPY --from=builder /src/target/release/bottlerocket-bootstrap-associate-eip /bottlerocket-bootstrap-associate-eip + +# Use the CA bundle from the Bottlerocket file system +ENV SSL_CERT_FILE=/.bottlerocket/rootfs/etc/pki/tls/certs/ca-bundle.crt + +# Enable more verbose logs +ENV RUST_BACKTRACE=full +ENV RUST_LOG=aws + +ENTRYPOINT [ "/bottlerocket-bootstrap-associate-eip" ] diff --git a/README.md b/README.md index 460e621..6637af9 100644 --- a/README.md +++ b/README.md @@ -64,3 +64,9 @@ journalctl -u bootstrap-containers@associate-eip.service ``` If you are unable to connect to the instance then wait 10 minutes and then check the EC2 instance system log. + +If you want more logging enabled then use the `debug` image: + +```toml +source = "public.ecr.aws/stefansundin/bottlerocket-bootstrap-associate-eip:debug" +``` diff --git a/src/main.rs b/src/main.rs index a78ad86..107dabe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,8 @@ #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), std::io::Error> { + env_logger::init(); + // Read the container user-data which contains the allocation id let allocation_id = std::fs::read_to_string("/.bottlerocket/bootstrap-containers/current/user-data")