Skip to content

Instantly share code, notes, and snippets.

@gdamjan
Last active April 27, 2020 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdamjan/ef3be348fbbb2b03790eb5d09d5c285c to your computer and use it in GitHub Desktop.
Save gdamjan/ef3be348fbbb2b03790eb5d09d5c285c to your computer and use it in GitHub Desktop.
ubuntu 20.04 + rustyd base docker image (https://github.com/KillingSpark/rustysd)
FROM rust:1-alpine as rust-builder
### Compile a static binary of rustysd
ARG RUSTYSD_VER=v0.2.0
WORKDIR /src
RUN rustup target add x86_64-unknown-linux-musl && \
wget https://github.com/KillingSpark/rustysd/archive/${RUSTYSD_VER}.tar.gz && \
tar xf ${RUSTYSD_VER}.tar.gz -C /src --strip-components=1
RUN cargo build --target x86_64-unknown-linux-musl --release
RUN strip --strip-unneeded \
target/x86_64-unknown-linux-musl/release/rustysd \
target/x86_64-unknown-linux-musl/release/rsdctl
### Now, once rustysd is compiled, just copy it to a base ubuntu:20.04 image
### thus getting a base image that you can just add apps and .service files to run
FROM ubuntu:20.04
COPY --from=rust-builder /src/target/x86_64-unknown-linux-musl/release/rustysd /src/target/x86_64-unknown-linux-musl/release/rsdctl /rustysd/
COPY --from=rust-builder /src/test_units/default.target /src/test_units/sockets.target /rustysd/unitfiles/
COPY rustysd_config.toml /rustysd/rustysd_config.toml
ENTRYPOINT ["/rustysd/rustysd", "-c", "/rustysd/"]
@gdamjan
Copy link
Author

gdamjan commented Apr 26, 2020

@gdamjan
Copy link
Author

gdamjan commented Apr 27, 2020

Example usage

you write your own unit for a service:

# test.service
[Unit]
Description=test service

[Service]
Type=simple
User=nobody
ExecStart=/bin/bash -c "while sleep 5; do echo test; done;"

[Install]
WantedBy=default.target

and then just create a docker image for the service based of this one and copy the unit in the proper place. The service will be started by rustysd when the image is started:

FROM gdamjan/ubuntu:20.04

COPY test.service /rustysd/unitfiles/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment