diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e3c9650 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +target/ +Cargo.lock +**/*.rs.bk +.idea diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..941141d --- /dev/null +++ b/.drone.yml @@ -0,0 +1,57 @@ +--- +kind: pipeline +type: docker +name: mirror-server + +steps: + - name: create-build-image + image: plugins/docker + settings: + username: + from_secret: docker-username + password: + from_secret: docker-password + registry: code.birch-tree.net + repo: code.birch-tree.net/dorian/mirror-server + target: BUILD + tags: + - build + cache_from: + - code.birch-tree.net/dorian/mirror-server:build + + - name: test + image: code.birch-tree.net/dorian/mirror-server:build + commands: + - cargo test + depends_on: + - create-build-image + + - name: create-release-image + image: plugins/docker + settings: + username: + from_secret: docker-username + password: + from_secret: docker-password + registry: code.birch-tree.net + repo: code.birch-tree.net/dorian/mirror-server + tags: + - 0.3.0 + - latest + cache_from: + - code.birch-tree.net/dorian/mirror-server:latest + - code.birch-tree.net/dorian/mirror-server:build + depends_on: + - test + + - name: create-debian-package + image: code.birch-tree.net/dorian/mirror-server:build + commands: + - cargo deb +# - TODO: Add a publish step based on the publish-deb.sh + depends_on: + - test + + +image_pull_secrets: + - docker-config diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..39f5973 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM rust:1.76 AS BUILD + +ENV APP_NAME=mirror-server +ENV APP_HOME=/srv/${APP_NAME} +RUN apt update \ + && apt install -y curl \ + && cargo install cargo-deb + +# Setup working env. +RUN mkdir -p ${APP_HOME} +WORKDIR ${APP_HOME} + +# Create build target cache. +RUN USER=root cargo init --bin . +COPY ["Cargo.toml", "Cargo.lock", "./"] +RUN cargo build \ + && cargo build --tests \ + && cargo build --release \ + && rm src/*.rs + +# Bring in the source +COPY ["src", "./src/"] + +# Build the example API. +RUN cargo build --release + +# Create the minimal server image. +FROM debian:buster-slim AS SERVER + +ENV APP_NAME=mirror-server +ENV APP_HOME=/srv/${APP_NAME} +RUN apt update + +RUN mkdir -p ${APP_HOME} +WORKDIR ${APP_HOME} + +COPY --from=BUILD ${APP_HOME}/target/release/${APP_NAME} /usr/local/bin/ +CMD ${APP_NAME} \ No newline at end of file diff --git a/README.md b/README.md index f979b80..92c0eec 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ A simple server for mirroring HTTP requests for testing. +[![Build Status](https://ci.birch-tree.net/api/badges/dorian/mirror-server/status.svg)](https://ci.birch-tree.net/dorian/mirror-server) + ## Getting Started * Use the latest stable version of Rust using rustup. @@ -29,9 +31,7 @@ sudo dpkg -i "mirror-server-${VERSION}_amd64.deb" * [x] Migrate actix to axum for easier maintainability. * [x] Add mirroring of JSON request. * [x] Add logging to server. -* [x] ~~Add convenience path to access logging for a certain date / records.~~ -* [ ] Create Docker image for mirror-server for easier distribution. +* [x] Create Docker image for mirror-server for easier distribution. * [ ] Add publishing of DEB and Docker image to DroneCI. -* [ ] Add OpenAPI/Swagger UI * [ ] Add documentation to the API. * [ ] Publish crate on .