Skip to content

Commit

Permalink
Add official Docker image #40
Browse files Browse the repository at this point in the history
  • Loading branch information
mre authored Dec 2, 2020
1 parent 1f78761 commit 936c544
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
target
assets
fixtures
21 changes: 21 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
name: lycheeverse/lychee
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
snapshot: true
tag_semver: true
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 936c544

Please sign in to comment.