Add support for building and running a Docker image
This commit is contained in:
parent
619261eb97
commit
dcbd18885a
|
@ -0,0 +1,18 @@
|
|||
# Local build and dev artifacts
|
||||
target
|
||||
|
||||
# Docker files
|
||||
Dockerfile*
|
||||
docker-compose*
|
||||
|
||||
# Git folder
|
||||
.git
|
||||
|
||||
# Dot files
|
||||
.gitignore
|
||||
|
||||
# TOML files
|
||||
autarco.toml*
|
||||
|
||||
# Documentation
|
||||
*.md
|
|
@ -0,0 +1,52 @@
|
|||
# Using multistage build:
|
||||
# https://docs.docker.com/develop/develop-images/multistage-build/
|
||||
# https://whitfin.io/speeding-up-rust-docker-builds/
|
||||
|
||||
########################## BUILD IMAGE ##########################
|
||||
# Rust build image to build Autarco Scraper's statically compiled binary
|
||||
FROM rust:1.45 as builder
|
||||
|
||||
# Build the dependencies first
|
||||
RUN USER=root cargo new --bin autarco-scraper
|
||||
WORKDIR ./autarco-scraper
|
||||
COPY ./Cargo.* ./
|
||||
RUN cargo build --release
|
||||
RUN rm src/*.rs
|
||||
|
||||
# Add the real project files from current folder
|
||||
ADD . ./
|
||||
|
||||
# Build the actual binary from the copied local files
|
||||
RUN rm ./target/release/deps/autarco_scraper*
|
||||
RUN cargo build --release
|
||||
|
||||
########################## RUNTIME IMAGE ##########################
|
||||
# Create new stage with a minimal image for the actual runtime image/container
|
||||
FROM debian:buster-slim
|
||||
|
||||
# Install cURL, Firefox and the Gecko Driver
|
||||
RUN apt-get update && \
|
||||
apt-get upgrade -y && \
|
||||
apt-get install -y --no-install-recommends ca-certificates curl firefox-esr jq && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
RUN export VERSION=$(curl -sL https://api.github.com/repos/mozilla/geckodriver/releases/latest | jq -r .tag_name); \
|
||||
curl -vsL https://api.github.com/repos/mozilla/geckodriver/releases/latest | jq -r .tag_name; \
|
||||
curl -sL "https://github.com/mozilla/geckodriver/releases/download/$VERSION/geckodriver-$VERSION-linux64.tar.gz" | \
|
||||
tar -xz -C /usr/local/bin && \
|
||||
chmod +x /usr/local/bin/geckodriver
|
||||
|
||||
# Copy the binary from the "builder" stage to the current stage
|
||||
RUN adduser --system --disabled-login --home /autarco-scraper --gecos "" --shell /bin/bash autarco-scraper
|
||||
COPY --from=builder /autarco-scraper/target/release/autarco-scraper /autarco-scraper
|
||||
|
||||
# Standard port on which Rocket launches
|
||||
EXPOSE 8000
|
||||
|
||||
# Set user to www-data
|
||||
USER autarco-scraper
|
||||
|
||||
# Set container home directory
|
||||
WORKDIR /autarco-scraper
|
||||
|
||||
# Run Autarco Scraper
|
||||
ENTRYPOINT [ "/autarco-scraper/autarco-scraper" ]
|
|
@ -0,0 +1,14 @@
|
|||
version: '3'
|
||||
|
||||
services:
|
||||
server:
|
||||
image: autarco-scraper:latest
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 8066:8000
|
||||
volumes:
|
||||
- ./autarco.toml:/autarco-scraper/autarco.toml
|
||||
environment:
|
||||
ROCKET_LOG: normal # Available levels are: off, debug, normal, critical
|
||||
shm_size: '2gb'
|
Reference in New Issue