diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..7ed7e0da3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM node:8 + +RUN mkdir -p /var/app/current +WORKDIR /var/app/current +COPY . ./ +RUN rm -rf ./node_modules +RUN npm install + +EXPOSE 8333 + diff --git a/README.md b/README.md index cc2541a39..1d4c47362 100644 --- a/README.md +++ b/README.md @@ -132,3 +132,35 @@ Additionally, if you set `FALLBACK=https://scratch.mit.edu`, be aware that click #### Windows Some users have experienced difficulties when trying to get our web client to work on Windows. One solution could be to use [Cygwin](https://www.cygwin.com/). If that doesn't work, you might want to use [Wubi](https://wiki.ubuntu.com/WubiGuide) (Windows XP, Vista, 7) or [Wubiuefi](https://github.com/hakuna-m/wubiuefi) (Windows 8 or higher). Wubi(uefi) is a Windows Installer for Ubuntu that allows you to have Ubuntu and Windows on one disk, without the need of an extra partition. + +#### Docker + +_This section is only relevant to the Scratch Team since it requires access to private repositories, so is not usable by 3rd party contributors._ + +A set of [Docker](https://www.docker.com/what-docker) related files are provided to create isolated [container](https://www.docker.com/what-container) environments suitable for end-to-end local development: + +* Dockerfile +* docker-compose.yml +* docker_entrypoint.sh + +##### Docker Quick Start (CLI) + +Make sure you already have the Scratch REST API running locally in its docker environment. + +``` +$ docker-compose up +``` + +After this has launched you will be able to access a running copy of `scratch-www` on port 8333 via `http://localhost:8333` + +##### Docker Configuration + +`Dockerfile` defines how a `scratch-www` docker image is created. + +`docker-compose.yml` takes care of launching `scratch-www` into a development environment that is composed of other components, such as the Scratch REST API server and the legacy Scratch code. If you have not already setup the Scratch REST API in your local environment, you will need to modify `docker-compose.yml` by removing `external: true` from: + +```yaml +networks: + scratchapi_scratch_network: + external: true +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..7f550e83f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +version: '3.4' +volumes: + npm_data: + runtime_data: + intl_data: + +networks: + scratchapi_scratch_network: + external: true + +services: + app: + container_name: scratch-www-app + hostname: scratch-www-app + environment: + - API_HOST=http://localhost:8491 + - FALLBACK=http://scratchr2-app:8080 + build: + context: ./ + dockerfile: Dockerfile + image: scratch-www:latest + command: ./docker_entrypoint.sh npm start + volumes: + - type: bind + source: ./ + target: /var/app/current + volume: + nocopy: true + - type: bind + source: ../scratch-gui + target: /var/app/current/scratch-gui + volume: + nocopy: true + - npm_data:/var/app/current/node_modules + - runtime_data:/runtime + - intl_data:/var/app/current/intl + ports: + - "8333:8333" + networks: + - scratchapi_scratch_network diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh new file mode 100755 index 000000000..5e95584c3 --- /dev/null +++ b/docker_entrypoint.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +echo "App Entrypoint" + +if [ ! -f /runtime/.translations ]; then + echo "Generating intl/translations" + make translations + touch /runtime/.translations +fi + +exec "$@"