Skip to content

Commit

Permalink
Add debug image.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Sep 12, 2022
1 parent 3840d6e commit ffce431
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 0 deletions.
3 changes: 3 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
58 changes: 58 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
46 changes: 46 additions & 0 deletions Dockerfile.debug
Original file line number Diff line number Diff line change
@@ -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" ]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit ffce431

Please sign in to comment.