From 08871e15b651a37774ea62802ab236cdf73bc11e Mon Sep 17 00:00:00 2001 From: Arghyadip Chakraborty Date: Thu, 25 Aug 2022 22:25:03 +0530 Subject: [PATCH] Automated docker build --- .github/workflows/docker.yml | 50 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 29 +++++++++++---------- Dockerfile | 34 +++++++++++++----------- 3 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..5051c6b --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,50 @@ +name: Docker Image + +on: + push: + branches: + - "master" + tags: + - "v*" + pull_request: + branches: + - "master" + +jobs: + docker_image: + name: Build & push docker image to DockerHub + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ secrets.DOCKERHUB_REPO }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - name: Setup QEMU + uses: docker/setup-qemu-action@v2 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build & push + uses: docker/build-push-action@v3 + with: + platforms: linux/amd64, linux/arm64 + push: ${{ github.ref_type == 'tag' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Cargo.toml b/Cargo.toml index 22cfee6..4b0821e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] -name="microbin" -version="1.1.0" -edition="2021" +name = "microbin" +version = "1.1.0" +edition = "2021" authors = ["Daniel Szabo "] license = "BSD-3-Clause" description = "Simple, performant, configurable, entirely self-contained Pastebin and URL shortener." @@ -11,20 +11,18 @@ repository = "https://github.com/szabodanika/microbin" keywords = ["pastebin", "pastabin", "microbin", "actix", "selfhosted"] categories = ["pastebins"] - - [dependencies] -actix-web="4" -actix-files="0.6.0" -serde={ version = "1.0", features = ["derive"] } +actix-web = "4" +actix-files = "0.6.0" +serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.80" bytesize = { version = "1.1", features = ["serde"] } -askama="0.10" -askama-filters={ version = "0.1.3", features = ["chrono"] } -chrono="0.4.19" -rand="0.8.5" -linkify="0.8.1" -clap={ version = "3.1.12", features = ["derive", "env"] } +askama = "0.10" +askama-filters = { version = "0.1.3", features = ["chrono"] } +chrono = "0.4.19" +rand = "0.8.5" +linkify = "0.8.1" +clap = { version = "3.1.12", features = ["derive", "env"] } actix-multipart = "0.4.0" futures = "0.3" sanitize-filename = "0.3.0" @@ -34,3 +32,6 @@ actix-web-httpauth = "0.6.0" lazy_static = "1.4.0" syntect = "5.0" +[profile.release] +lto = true +strip = true diff --git a/Dockerfile b/Dockerfile index 9f8858e..3b823f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,27 @@ -# latest rust will be used to build the binary -FROM rust:latest as builder +FROM rust:latest as build -# the temporary directory where we build -WORKDIR /usr/src/microbin +WORKDIR /app -# copy sources to /usr/src/microbin on the temporary container COPY . . -# run release build -RUN cargo build --release +RUN \ + DEBIAN_FRONTEND=noninteractive \ + apt-get update &&\ + apt-get -y install ca-certificates tzdata &&\ + cargo build --release -# create final container using slim version of debian -FROM debian:buster-slim +FROM debian:bullseye-slim -# microbin will be in /usr/local/bin/microbin/ -WORKDIR /usr/local/bin +WORKDIR /app -# copy built exacutable -COPY --from=builder /usr/src/microbin/target/release/microbin /usr/local/bin/microbin +COPY --from=build \ + /usr/share/zoneinfo \ + /usr/share/zoneinfo +COPY --from=build \ + /etc/ssl/certs/ca-certificates.crt \ + /etc/ssl/certs/ca-certificates.crt +COPY --from=build \ + /app/target/release/microbin \ + /usr/bin/microbin -# run the binary -CMD ["microbin"] +ENTRYPOINT ["microbin"] \ No newline at end of file