From 4a99bb938c19e5e39214c7033644dda94e5f010a Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sat, 2 Apr 2022 13:45:04 +0200 Subject: [PATCH] Added Dockerfile & CI deploy --- .dockerignore | 5 +++++ .gitignore | 1 + .woodpecker.yml | 23 +++++++++++++++++++++++ Cargo.toml | 4 ++++ Dockerfile | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 .dockerignore create mode 100644 .woodpecker.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fa11f07 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +* + +!src/ +!Cargo.toml +!Cargo.lock diff --git a/.gitignore b/.gitignore index ea8c4bf..ac67213 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/data/ diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..ab093e4 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,23 @@ +platform: linux/amd64 +branch: main + +pipeline: + release: + image: 'plugins/docker' + settings: + repo: 'chewingbever/site' + tag: + - 'latest' + - "${CI_COMMIT_TAG}" + secrets: + - 'docker_username' + - 'docker_password' + event: tag + + deploy: + image: 'curlimages/curl' + secrets: + - 'webhook' + commands: + - curl -XPOST --fail -s "$WEBHOOK" + event: tag diff --git a/Cargo.toml b/Cargo.toml index 56cefe2..31140a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,10 @@ version = "0.0.0" edition = "2021" publish = false +[[bin]] +path = "src/main.rs" +name = "site" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2c609af --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM rust:1.59-alpine3.15 AS builder + +ARG DI_VER=1.2.5 + +WORKDIR /app + +RUN apk update && apk add --no-cache build-base + +# Build dumb-init +RUN wget -O - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.tar.gz" | tar -xzf - && \ + cd "dumb-init-${DI_VER}" && \ + make SHELL=/bin/sh && \ + mv dumb-init .. && \ + cd .. + +COPY . ./ + +RUN cargo build --release + + +FROM alpine:3.15 + +COPY --from=builder /app/target/release/site /bin/site +COPY --from=builder /app/dumb-init /bin/dumb-init + +# Create a non-root user & make sure it can write to the data directory +RUN set -x && \ + adduser -u 82 -D -S -G www-data www-data && \ + mkdir /data && \ + chown -R www-data:www-data /data + +ENV DATA_DIR=/data + +WORKDIR /data + +USER www-data:www-data + +ENTRYPOINT [ "/bin/dumb-init", "--" ] +CMD [ "/bin/site" ] + +