Skip to content

Commit

Permalink
Fix bug 1478066 - Use volumes instead of symlinks in docker dev envir… (
Browse files Browse the repository at this point in the history
mozilla#1024)

* Fix bug 1478066 - Use volumes instead of symlinks in docker dev environment.

* Use docker-compose everywhere possible.
This also removes the new useless run_tests_in_docker.sh file, that was quite inconsistent with our use of the Makefile. Everything is a lot more streamlined and simple now.
  • Loading branch information
adngdb authored Jul 25, 2018
1 parent a84b584 commit 67c22a3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 134 deletions.
46 changes: 18 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ help:
@echo " clean Forces a rebuild of docker containers"
@echo " shell Opens a Bash shell"
@echo " test Runs the Python test suite"
@echo " test-frontend Runs the new frontend's test suite"
@echo " flow Runs the Flow type checker on the frontend code"
@echo " loaddb Load a database dump into postgres, file name in DB_DUMP_FILE"
@echo " build-frontend Builds the frontend static files"
@echo " build-frontend-w Watches the frontend static files and builds on change\n"

.docker-build:
make build

assets:
mkdir -p assets

build:
cp ./docker/config/webapp.env.template ./docker/config/webapp.env
sed -i -e 's/#SITE_URL#/$(subst /,\/,${SITE_URL})/g' ./docker/config/webapp.env
Expand All @@ -46,43 +45,34 @@ clean:
rm .docker-build

test:
./docker/run_tests_in_docker.sh ${ARGS}
${DC} run --rm webapp /app/docker/run_tests.sh

test-frontend:
${DOCKER} run --rm \
-v `pwd`:/app \
--workdir /app/frontend \
--tty \
--interactive \
local/pontoon yarn test
${DC} run --rm -w /app/frontend webapp yarn test

flow:
${DOCKER} run --rm \
-v `pwd`:/app \
-e SHELL=bash \
--workdir /app/frontend \
--tty --interactive \
local/pontoon yarn flow:dev
${DC} run --rm -w /app/frontend -e SHELL=/bin/bash webapp yarn flow:dev

shell:
./docker/run_tests_in_docker.sh --shell
${DC} run --rm webapp /bin/bash

loaddb:
# Stop connections to the database so we can drop it.
-${DC} stop webapp
-${DOCKER} exec -i `${DC} ps -q postgresql` dropdb -U pontoon pontoon
${DOCKER} exec -i `${DC} ps -q postgresql` createdb -U pontoon pontoon
# Make sure the postgresql container is running.
-${DC} start postgresql
-${DC} exec postgresql dropdb -U pontoon pontoon
${DC} exec postgresql createdb -U pontoon pontoon
# Note: docker-compose doesn't support the `-i` (--interactive) argument
# that we need to send the dump file through STDIN. We thus are forced to
# use docker here instead.
${DOCKER} exec -i `${DC} ps -q postgresql` pg_restore -U pontoon -d pontoon -O < ${DB_DUMP_FILE}

build-frontend: assets
${DC} run webapp npm run build
build-frontend:
${DC} run --rm webapp npm run build

build-frontend-w: assets
${DOCKER} run --rm \
-v `pwd`:/app \
--workdir /app \
-e LOCAL_USER_ID=$UID \
--tty --interactive \
local/pontoon npm run build-w
build-frontend-w:
${DC} run --rm webapp npm run build-w

# Old targets for backwards compatibility.
dockerbuild: build
Expand Down
Empty file modified README.md
100755 → 100644
Empty file.
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ services:
- "8000:8000"
- "3000:3000"
volumes:
- .:/app
entrypoint:
- ./docker/entrypoint_webapp.sh
- ./pontoon:/app/pontoon
- ./frontend/src:/app/frontend/src
- ./frontend/public:/app/frontend/public
- ./tests:/app/tests

postgresql:
build:
Expand Down
36 changes: 6 additions & 30 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,15 @@ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs yarn

# Create some folders and give them to the app user
RUN mkdir -p /webapp-frontend-deps && \
chown app:app /webapp-frontend-deps

RUN chown app:app /app
COPY . /app/

# Create the folder for front-end assets
RUN mkdir -p /webapp-frontend-deps/assets && \
chown app:app /webapp-frontend-deps/assets

# Create the folders for Translate.Next
RUN mkdir -p /app/frontend && \
mkdir -p /webapp-frontend-deps/frontend/build

RUN chown -R app:app /webapp-frontend-deps
RUN mkdir -p /app/assets

# Install node requirements
COPY ./package.json /webapp-frontend-deps/package.json
COPY ./package-lock.json /webapp-frontend-deps/package-lock.json
RUN cd /webapp-frontend-deps && npm install

COPY ./frontend/package.json /webapp-frontend-deps/frontend/package.json
COPY ./frontend/yarn.lock /webapp-frontend-deps/frontend/yarn.lock
RUN cd /webapp-frontend-deps/frontend && yarn install

# Link to the node modules installed with npm and yarn. We install those in
# different folders because when using this container in development,
# we replace the /app folder with a volume. By putting those dependencies
# outside of /app, we can reuse them more easily.
RUN ln -s /webapp-frontend-deps/node_modules /app/node_modules && \
ln -s /webapp-frontend-deps/assets /app/assets && \
ln -s /webapp-frontend-deps/frontend/node_modules /app/frontend/node_modules && \
ln -s /webapp-frontend-deps/frontend/build /app/frontend/build
RUN cd /app && npm install
RUN cd /app/frontend && yarn install

COPY . /app/
COPY ./docker/config/webapp.env /app/.env

# Python environment variables
Expand All @@ -82,4 +56,6 @@ RUN cd /app/frontend/ && yarn build
# static files.
RUN cd /app/ && python manage.py collectstatic --noinput

RUN chown -R app:app /app

CMD ["/app/docker/run_webapp.sh"]
19 changes: 0 additions & 19 deletions docker/entrypoint_webapp.sh

This file was deleted.

51 changes: 0 additions & 51 deletions docker/run_tests_in_docker.sh

This file was deleted.

3 changes: 0 additions & 3 deletions docker/run_webapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

# Prepares then runs the webapp.

echo ">>> Prepare revision file"
git rev-parse HEAD > static/revision.txt

echo ">>> Setting up the db for Django"
python manage.py migrate

Expand Down

0 comments on commit 67c22a3

Please sign in to comment.