From 0e01a95c942fc527d1c7d42a665cd05fcc3a6427 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Fri, 30 Apr 2021 17:08:20 -0500 Subject: [PATCH] Initial dockerfile setup and blanked out docker-compose files --- Dockerfile | 87 ++++++++++++++ docker-compose.dev.yml | 72 ++++++------ docker-compose.prod.yml | 40 +++---- docker-compose.yml | 246 ++++++++++++++++++++-------------------- 4 files changed, 266 insertions(+), 179 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6dd7059 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,87 @@ +# -------------------------------------------------------------------------------------------------- +# NOTE: This Dockerfile was designed to be run with BuildKit. +# +# Enable BuildKit using: +# $ export DOCKER_BUILDKIT=1 +# $ export COMPOSE_DOCKER_CLI_BUILD=1 +# -------------------------------------------------------------------------------------------------- + +# The service to build +ARG SERVICE + +# The base image to use +ARG BASE=base-alpine + +# Base Definitions --------------------------------------------------------------------------------- + +# Alpine base definition +FROM node:14-alpine AS base-alpine + +# Alpine dev definition +FROM base-alpine AS base-alpine-dev +RUN apk add build-base python3 + +# Slim base definition +FROM node:14-slim AS base-slim + +# Slim dev definition +FROM base-slim AS base-slim-dev + +# Development Image -------------------------------------------------------------------------------- + +# Define the base image +FROM ${BASE}-dev AS dev +ARG SERVICE +WORKDIR /opt/app + +# Environment configuration +ENV PATH "/app/node_modules/.bin:$PATH" +RUN echo "#!/bin/sh" >> /bin/lerna && \ + echo '( cd /opt/app && ./node_modules/.bin/lerna "$@" )' >> /bin/lerna && \ + chmod +x /bin/lerna + +# Copy over Lerna stuff +COPY lerna.json package.json tsconfig.json ./ +RUN yarn install + +# Symlink the requested service to /app +RUN ln -s /opt/app/services/${SERVICE} /app +WORKDIR /app + +# Build Definitions -------------------------------------------------------------------------------- + +# Create the builder image with all dependencies +FROM ${BASE}-dev AS builder +ARG SERVICE +WORKDIR /app +RUN yarn global add lerna typescript rimraf +COPY scripts scripts +COPY lerna.json package.json tsconfig.json yarn.lock ./ +RUN yarn install +COPY packages packages +COPY services/${SERVICE}/package.json ./services/${SERVICE}/ + +# Cache an image containing only the prod-dependencies +FROM builder AS prod-deps +RUN lerna bootstrap -- --production --no-optional +RUN yarn run export:deps + +# Build the service +FROM builder AS build +ARG SERVICE +COPY services/${SERVICE} ./services/${SERVICE} +RUN lerna clean --yes && lerna bootstrap && lerna run clean && lerna run build +RUN yarn run export:builds + +# Return to base image with the compiled files and production dependencies +FROM ${BASE} AS prod +ARG SERVICE +WORKDIR /app +COPY --from=prod-deps /app/build /opt +COPY --from=build /app/build /opt +RUN for link in $(find /opt/services -type l); do dir=$(readlink -f $link); rm $link; ln -s $dir $link; done +RUN mv /opt/services/${SERVICE}/* /app && rm -rf /opt/services +# TODO: Should remove unnecessary packages that were included + +# Default entrypoint +ENTRYPOINT "/bin/sh" diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 1b469d8..d5fb806 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,45 +1,45 @@ version: "3.9" services: - request: - build: - target: base - ports: - - 3001:3001 - volumes: - - ./request:/app - entrypoint: "/bin/sh" - tty: true + # request: + # build: + # target: base + # ports: + # - 3001:3001 + # volumes: + # - ./request:/app + # entrypoint: "/bin/sh" + # tty: true - seeker: - build: - target: base-dev - volumes: - - ./seeker:/app - entrypoint: "/bin/sh" - tty: true + # seeker: + # build: + # target: base-dev + # volumes: + # - ./seeker:/app + # entrypoint: "/bin/sh" + # tty: true - torrent_webui: - build: - target: base - ports: - - 3000:3000 - volumes: - - ./torrent-webui:/app - entrypoint: "/bin/sh" - tty: true + # torrent_webui: + # build: + # target: base + # ports: + # - 3000:3000 + # volumes: + # - ./torrent-webui:/app + # entrypoint: "/bin/sh" + # tty: true - torrent_client: - build: - target: base - volumes: - - ./torrent-client:/app - # ulimits: - # core: - # hard: -1 - # soft: -1 - entrypoint: "/bin/sh" - tty: true + # torrent_client: + # build: + # target: base + # volumes: + # - ./torrent-client:/app + # # ulimits: + # # core: + # # hard: -1 + # # soft: -1 + # entrypoint: "/bin/sh" + # tty: true # torrent_client: # build: diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index e6c9b6e..bc7c66c 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,26 +1,26 @@ version: "3.9" services: - request: - build: - target: prod - environment: - NODE_ENV: production + # request: + # build: + # target: prod + # environment: + # NODE_ENV: production - seeker: - build: - target: prod - environment: - NODE_ENV: production + # seeker: + # build: + # target: prod + # environment: + # NODE_ENV: production - torrent_webui: - build: - target: prod - environment: - NODE_ENV: production + # torrent_webui: + # build: + # target: prod + # environment: + # NODE_ENV: production - torrent_client: - build: - target: prod - environment: - NODE_ENV: production + # torrent_client: + # build: + # target: prod + # environment: + # NODE_ENV: production diff --git a/docker-compose.yml b/docker-compose.yml index 3fa5890..74c5761 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,90 +1,90 @@ version: "3.9" services: - request: - build: - context: ./request - depends_on: - - "database" - - "torrent_client" - env_file: - - ./request/.env - links: - - "database" - - "torrent_client" - ports: - - 3200:3200 - restart: unless-stopped - secrets: - - app_key - - discord_bot_key - - mysql_root_password - - plex_token - - tmdb_key - - tvdb_key - - tvdb_pin - user: ${UID}:${GID} - volumes: - - var:/var/autoplex + # request: + # build: + # context: ./request + # depends_on: + # - "database" + # - "torrent_client" + # env_file: + # - ./request/.env + # links: + # - "database" + # - "torrent_client" + # ports: + # - 3200:3200 + # restart: unless-stopped + # secrets: + # - app_key + # - discord_bot_key + # - mysql_root_password + # - plex_token + # - tmdb_key + # - tvdb_key + # - tvdb_pin + # user: ${UID}:${GID} + # volumes: + # - var:/var/autoplex - seeker: - build: - context: ./seeker - depends_on: - - "database" - - "torrent_client" - env_file: - - ./seeker/.env - links: - - "database" - - "torrent_client" - restart: unless-stopped - secrets: - - mysql_root_password - user: ${UID}:${GID} - volumes: - - var:/var/autoplex + # seeker: + # build: + # context: ./seeker + # depends_on: + # - "database" + # - "torrent_client" + # env_file: + # - ./seeker/.env + # links: + # - "database" + # - "torrent_client" + # restart: unless-stopped + # secrets: + # - mysql_root_password + # user: ${UID}:${GID} + # volumes: + # - var:/var/autoplex - torrent_webui: - build: - context: ./torrent-webui - depends_on: - - "database" - - "torrent_client" - env_file: - - ./torrent-webui/.env - links: - - "database" - - "torrent_client" - ports: - - 3300:3300 - secrets: - - mysql_root_password - user: ${UID}:${GID} - volumes: - - var:/var/autoplex + # torrent_webui: + # build: + # context: ./torrent-webui + # depends_on: + # - "database" + # - "torrent_client" + # env_file: + # - ./torrent-webui/.env + # links: + # - "database" + # - "torrent_client" + # ports: + # - 3300:3300 + # secrets: + # - mysql_root_password + # user: ${UID}:${GID} + # volumes: + # - var:/var/autoplex - torrent_client: - build: - context: ./torrent-client - depends_on: - - "database" - - "vpn" - env_file: - - ./torrent-client/.env - healthcheck: - test: ["CMD", "ping", "-q", "-c1", "google.com"] - interval: 5m - timeout: 10s - retries: 3 - start_period: 5m - network_mode: service:vpn - restart: unless-stopped - secrets: - - mysql_root_password - user: ${UID}:${GID} - volumes: - - var:/var/autoplex + # torrent_client: + # build: + # context: ./torrent-client + # depends_on: + # - "database" + # - "vpn" + # env_file: + # - ./torrent-client/.env + # healthcheck: + # test: ["CMD", "ping", "-q", "-c1", "google.com"] + # interval: 5m + # timeout: 10s + # retries: 3 + # start_period: 5m + # network_mode: service:vpn + # restart: unless-stopped + # secrets: + # - mysql_root_password + # user: ${UID}:${GID} + # volumes: + # - var:/var/autoplex # torrent_client: # build: @@ -106,49 +106,49 @@ services: # - ./.volumes/storage:/storage/default # - var:/var/autoplex - database: - image: mysql - command: --default-authentication-plugin=mysql_native_password - environment: - MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password - ports: - - 33061:3306 - restart: unless-stopped - security_opt: - - seccomp=unconfined - secrets: - - mysql_root_password - volumes: - - ./database/init:/docker-entrypoint-initdb.d - - mysql:/var/lib/mysql + # database: + # image: mysql + # command: --default-authentication-plugin=mysql_native_password + # environment: + # MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password + # ports: + # - 33061:3306 + # restart: unless-stopped + # security_opt: + # - seccomp=unconfined + # secrets: + # - mysql_root_password + # volumes: + # - ./database/init:/docker-entrypoint-initdb.d + # - mysql:/var/lib/mysql - vpn: - build: - context: ./vpn - cap_add: - - net_admin - command: - - '-f ""' - environment: - TZ: "CST6CDT" - links: - - "database" - networks: - - default - read_only: true - tmpfs: - - /run - - /tmp - restart: unless-stopped - secrets: - - vpn_auth - security_opt: - - label:disable - stdin_open: true - tty: true - volumes: - - /dev/net:/dev/net:z - - ./.volumes/vpn:/vpn + # vpn: + # build: + # context: ./vpn + # cap_add: + # - net_admin + # command: + # - '-f ""' + # environment: + # TZ: "CST6CDT" + # links: + # - "database" + # networks: + # - default + # read_only: true + # tmpfs: + # - /run + # - /tmp + # restart: unless-stopped + # secrets: + # - vpn_auth + # security_opt: + # - label:disable + # stdin_open: true + # tty: true + # volumes: + # - /dev/net:/dev/net:z + # - ./.volumes/vpn:/vpn secrets: app_key: