From 936c5440b1f5bc400cc13443515978de377fc080 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 2 Dec 2020 23:43:05 +0100 Subject: [PATCH] Add official Docker image #40 --- .dockerignore | 4 ++++ .github/workflows/docker.yml | 21 ++++++++++++++++ Dockerfile | 46 ++++++++++++++++++++++++++++++++++++ Makefile | 27 +++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..4da1a91126 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +target +assets +fixtures diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000000..64f1d17fb9 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,21 @@ +on: + push: + branches: + - master + tags: + - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10 + +name: Publish Docker Image +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@3.01 + with: + name: lycheeverse/lychee + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + snapshot: true + tag_semver: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..027ca3d314 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +FROM rust:latest as builder + +RUN USER=root cargo new --bin lychee +WORKDIR /lychee + +# Just copy the Cargo.toml and trigger a build so +# that we compile our dependencies only. +# This way we avoid layer cache invalidation +# if our dependencies haven't changed, +# resulting in faster builds. +COPY Cargo.toml Cargo.toml +RUN cargo build --release +RUN rm src/*.rs + +# Copy the source code and run the build again. +# This should only compile lychee itself as the +# dependencies were already built above. +ADD . ./ +RUN rm ./target/release/deps/lychee* +RUN cargo build --release + + +# Our production image starts here, which uses +# the files from the builder image above. +FROM debian:buster-slim +ARG APP=/usr/src/lychee + +RUN apt-get update \ + && apt-get install -y ca-certificates tzdata \ + && rm -rf /var/lib/apt/lists/* + +ENV TZ=Etc/UTC \ + APP_USER=lychee + +RUN groupadd $APP_USER \ + && useradd -g $APP_USER $APP_USER \ + && mkdir -p ${APP} + +COPY --from=builder /lychee/target/release/lychee ${APP}/lychee + +RUN chown -R $APP_USER:$APP_USER ${APP} + +USER $APP_USER +WORKDIR ${APP} + +ENTRYPOINT [ "./lychee" ] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..f79461469a --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +# Needed SHELL since I'm using zsh +SHELL := /bin/bash +IMAGE_NAME := "lycheeverse/lychee" + +.PHONY: help +help: ## This help message + @echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)" + +.PHONY: docker-build +docker-build: ## Build Docker image + docker build -t $(IMAGE_NAME) . + +.PHONY: docker-run +docker-run: ## Run Docker image + docker run $(IMAGE_NAME) + +.PHONY: docker-push +docker-push: ## Push image to Docker Hub + docker push $(IMAGE_NAME) + +.PHONY: build-local +build: ## Build Rust code locally + cargo build + +.PHONY: run +run: ## Run Rust code locally + cargo run