diff --git a/Makefile b/Makefile index 752336f..ba05eea 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,7 @@ install: fiche clean: rm -f fiche +docker: + docker build --tag solusipse/fiche --build-arg ALPINE_VERSION=3.20 . + .PHONY: clean diff --git a/README.md b/README.md index e3922d5..d13bf0c 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ To use fiche you have to have netcat installed. You probably already have it - t # Server-side usage -## Installation +## Installation (source) 1. Clone: @@ -131,6 +131,24 @@ To use fiche you have to have netcat installed. You probably already have it - t sudo make install ``` +## Installation (docker) + +1. Clone: + + ``` + git clone https://github.com/solusipse/fiche.git + ``` +2. Customize environment variables + + ``` + nano docker-compose.yml + ``` +3. Launch + + ``` + docker compose up -d + ``` + ### Using Ports on FreeBSD To install the port: `cd /usr/ports/net/fiche/ && make install clean`. To add the package: `pkg install fiche`. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..27eea46 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +--- +services: + fiche: + image: solusipse/fiche + restart: unless-stopped + environment: + - HTTPS=no + - OUTPUT_DIRECTORY=/opt/fiche/code + - DOMAIN=example.com + - SLUG_SIZE=4 + - BUFFER_SIZE=32768 + ports: + - 9999:9999 + volumes: + - fiche-code:/opt/fiche/code + web: + image: nginx + restart: unless-stopped + ports: + - 80:80 + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + - ./nginx-site.conf:/etc/nginx/conf.d/default.conf + - fiche-code:/var/www/html + +volumes: + fiche-code: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..b763fa5 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env sh +set -e +args="" + +# Check environment variables and set construct the cmd line accordingly +if [ "${HTTPS}" = "yes" ] || [ "${HTTPS}" = "true" ]; then + args="${ARGS} -S" +fi +if [ ! -z "${OUTPUT_DIRECTORY}" ]; then + args="${args} -o ${OUTPUT_DIRECTORY}" +fi +if [ ! -z "${DOMAIN}" ]; then + args="${ARGS} -d ${DOMAIN}" +fi +if [ ! -z "${SLUG_SIZE}" ]; then + args="${ARGS} -s ${SLUG_SIZE}" +fi +if [ ! -z "${BUFFER_SIZE}" ]; then + args="${ARGS} -B ${BUFFER_SIZE}" +fi +if [ ! -z "${LOG_FILE}" ]; then + args="${ARGS} -b ${LOG_FILE}" +fi + +### +# FUTURE DEVELOPMENT +### +#if [ ! -z "${WHITELIST_FILE}" ]; then +# args="${ARGS} -w ${WHITELIST_FILE}" +#fi +#if [ ! -z "${BANLIST_FILE}" ]; then +# args="${ARGS} -b ${BANLIST_FILE}" +#fi + +/usr/local/bin/fiche "${args}" & +FICHE_PID=$! + +# Close trap function +close() { + kill -SIGTERM "$FICHE_PID" +} + +# Trap SIGTERM and SIGINT +trap "close" SIGTERM +trap "close" SIGINT + +# Wait for Fiche (in case it crashes, etc) +wait "$FICHE_PID" diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..146894f --- /dev/null +++ b/dockerfile @@ -0,0 +1,25 @@ +ARG ALPINE_VERSION="3" +# Stage 1 · builder +FROM alpine:${ALPINE_VERSION} AS builder + +WORKDIR /usr/src/fiche +COPY . . + +RUN apk update && apk add \ + make \ + gcc \ + g++ && \ + make && \ + make install && \ + make clean + +# Stage 2 · app +FROM alpine:${ALPINE_VERSION} AS app + +WORKDIR /opt/fiche +COPY --from=builder /usr/local/bin/fiche /usr/local/bin/fiche +COPY docker-entrypoint.sh /docker-entrypoint.sh + +VOLUME /opt/fiche/code + +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/nginx-site.conf b/nginx-site.conf new file mode 100644 index 0000000..c2b4f33 --- /dev/null +++ b/nginx-site.conf @@ -0,0 +1,16 @@ +server { + listen 80; + server_name localhost; + root /var/www/html; + index index.txt index.html; + charset utf-8; + + location / { + try_files $uri $uri/ =404; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..9f0af37 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,31 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + gzip off; + server_tokens off; + + include /etc/nginx/conf.d/*.conf; +}