From 6b04a7edd6ff2a4041208652ba59f4d3713ec472 Mon Sep 17 00:00:00 2001 From: Marcin Bonk Date: Tue, 30 Nov 2021 03:08:38 +0100 Subject: [PATCH] Added docker support --- .docker/nginx/conf.d/domain.conf | 27 +++++++++++++++ .docker/node/docker-entrypoint.sh | 18 ++++++++++ .docker/php/docker-entrypoint.sh | 9 +++++ Dockerfile | 57 +++++++++++++++++++++++++++++++ README.md | 20 ++++++++--- docker-compose.yml | 38 +++++++++++++++++++++ 6 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 .docker/nginx/conf.d/domain.conf create mode 100644 .docker/node/docker-entrypoint.sh create mode 100644 .docker/php/docker-entrypoint.sh create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.docker/nginx/conf.d/domain.conf b/.docker/nginx/conf.d/domain.conf new file mode 100644 index 00000000..57ec9f80 --- /dev/null +++ b/.docker/nginx/conf.d/domain.conf @@ -0,0 +1,27 @@ +server { + listen 80 default_server; + + root /var/www/www; + index index.php index.html index.htm; + + client_max_body_size 100M; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + try_files $uri /index.php =404; + fastcgi_pass php:9000; + fastcgi_index index.php; + + fastcgi_buffer_size 128k; + fastcgi_buffers 4 256k; + fastcgi_busy_buffers_size 256k; + + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + #fixes timeouts + fastcgi_read_timeout 600; + include fastcgi_params; + } +} diff --git a/.docker/node/docker-entrypoint.sh b/.docker/node/docker-entrypoint.sh new file mode 100644 index 00000000..ecd73af8 --- /dev/null +++ b/.docker/node/docker-entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- node "$@" +fi + +if [ "$1" = 'node' ] || [ "$1" = 'yarn' ]; then + yarn install + + >&2 echo "Waiting for PHP to be ready..." + until nc -z "$PHP_HOST" "$PHP_PORT"; do + sleep 1 + done +fi + +exec "$@" diff --git a/.docker/php/docker-entrypoint.sh b/.docker/php/docker-entrypoint.sh new file mode 100644 index 00000000..ab5e1f3f --- /dev/null +++ b/.docker/php/docker-entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- php-fpm "$@" +fi + +exec docker-php-entrypoint "$@" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3b561186 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +ARG PHP_VERSION=8.0 +ARG NODE_VERSION=14 +ARG NGINX_VERSION=1.16 + +######### PHP CONFIG +FROM php:${PHP_VERSION}-fpm-alpine as php + +WORKDIR /srv/app +COPY www www/ + +EXPOSE 9000 + +COPY ./.docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint +RUN chmod +x /usr/local/bin/docker-entrypoint + +ENTRYPOINT ["docker-entrypoint"] +CMD ["php-fpm"] + +######### NODE CONFIG +FROM node:${NODE_VERSION}-alpine as node + +WORKDIR /srv/app + +RUN apk update; \ + apk add yarn; +RUN apk add --no-cache --virtual .build-deps alpine-sdk python3 + +# prevent the reinstallation of vendors at every changes in the source code +COPY package.json yarn.lock ./ +COPY tsconfig.json tslint.json webpack.config.js ./ +COPY src src/ +COPY styles styles/ +COPY templates templates/ +COPY bin bin/ +COPY data data/ + +RUN set -eux; \ + yarn install; \ + yarn cache clean; \ + yarn build + +RUN apk del .build-deps + +COPY ./.docker/node/docker-entrypoint.sh /usr/local/bin/docker-entrypoint +RUN chmod +x /usr/local/bin/docker-entrypoint + +ENTRYPOINT ["docker-entrypoint"] +CMD ["yarn", "start"] + +######### NGINX CONFIG +FROM nginx:${NGINX_VERSION}-alpine as nginx +COPY .docker/nginx/conf.d/domain.conf /etc/nginx/conf.d/default.conf + +WORKDIR /srv/app + +COPY --from=node /srv/app/www/assets www/assets +COPY --from=php /srv/app/www/index.php www/index.php diff --git a/README.md b/README.md index 624a2d02..058b9a33 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # SatisfactoryTools Satisfactory Tools for planning and building the perfect base. +# Standard application development ## Requirements - node.js - yarn @@ -11,15 +12,26 @@ Satisfactory Tools for planning and building the perfect base. - `yarn install` - Set up a virtual host pointing to `/www` directory (using e.g. Apache or ngnix) +## Development +Run `yarn start` to start the automated build process. It will watch over the code and rebuild it on change. + +# Dockerized application development +## Requirements +- docker +- docker-compose + +## Installation / Building +- docker build . + +## Development +- docker compose up -d + ## Contributing Any pull requests are welcome, though some rules must be followed: - try to follow current coding style (there's `tslint` and `.editorconfig`, those should help you with that) - one PR per feature - all PRs must target `dev` branch -## Development -Run `yarn start` to start the automated build process. It will watch over the code and rebuild it on change. - ## Updating data Get the latest Docs.json from your game installation and place it into `data` folder. Then run `yarn parseDocs`command and the `data.json` file would get updated automatically. @@ -33,4 +45,4 @@ First you need to extract the images out of the game pack. You need `umodel` (UE .\umodel.exe -path="C:\Program Files\Epic Games\SatisfactoryExperimental\FactoryGame\Content\Paks" -out=".\out256" -png -export *_256_New.uasset -game=ue4.22 ``` -After the export is done, copy the resulting `out256` folder to `data/icons`. Then run `yarn generateImages`, which will automatically generate the images in correct sizes and places. `yarn parseDocs` has to be run before this command, if it wasn't run in the previous step. +After the export is done, copy the resulting `out256` folder to `data/icons`. Then run `yarn generateImages`, which will automatically generate the images in correct sizes and places. `yarn parseDocs` has to be run before this command, if it wasn't run in the previous step. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..312af2ea --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: "3.2" +services: + nginx: + build: + context: . + target: nginx + depends_on: + - php + - node + ports: + - "80:80" + links: + - php + volumes: + - ./.docker/nginx/conf.d/domain.conf:/etc/nginx/conf.d/default.conf:ro + - ./www:/var/www/www:ro + php: + build: + context: . + target: php + depends_on: + - node + volumes: + - ./www:/var/www/www + - ./node_modules:/var/www/node_modules + node: + build: + context: . + target: node + environment: + PHP_HOST: php + PHP_PORT: 9000 + volumes: + - ./src:/var/www/src + - ./styles:/var/www/styles + - ./templates:/var/www/templates + - ./bin:/var/www/bin + - ./data:/var/www/data