зеркало из https://github.com/mozilla/pontoon.git
Fix bug 1478066 - Use volumes instead of symlinks in docker dev envir… (#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.
This commit is contained in:
Родитель
a84b5842dd
Коммит
67c22a3356
46
Makefile
46
Makefile
|
@ -17,6 +17,8 @@ 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"
|
||||
|
@ -24,9 +26,6 @@ help:
|
|||
.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
|
||||
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
RUN cd /app && npm install
|
||||
RUN cd /app/frontend && yarn 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
|
||||
|
||||
COPY . /app/
|
||||
COPY ./docker/config/webapp.env /app/.env
|
||||
|
||||
# Python environment variables
|
||||
|
@ -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"]
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Make sure links to the node modules are created.
|
||||
ln -s /webapp-frontend-deps/node_modules /app/node_modules
|
||||
ln -s /webapp-frontend-deps/frontend/node_modules /app/frontend/node_modules
|
||||
ln -s /webapp-frontend-deps/frontend/build /app/frontend/build
|
||||
ln -s /webapp-frontend-deps/assets /app/assets
|
||||
|
||||
# Add local user
|
||||
# Either use the LOCAL_USER_ID if passed in at runtime or
|
||||
# fallback
|
||||
|
||||
USER_ID=${LOCAL_USER_ID:-10001}
|
||||
|
||||
echo "Starting with UID : $USER_ID"
|
||||
usermod -o -u $USER_ID app
|
||||
chown -R app:app /app
|
||||
export HOME=/home/app
|
||||
exec /usr/local/bin/gosu app "$@"
|
|
@ -1,51 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Script that sets up the docker environment to run the tests in and runs the
|
||||
# tests.
|
||||
|
||||
# Pass --shell to run a shell in the test container.
|
||||
|
||||
# Failures should cause setup to fail.
|
||||
set -e
|
||||
|
||||
DC="$(which docker-compose)"
|
||||
|
||||
# Use the same image we use for building docker images because it'll be cached
|
||||
# already.
|
||||
BASEIMAGENAME="local/pontoon_base"
|
||||
|
||||
# Start services in background (this is idempotent).
|
||||
echo "Starting services in the background..."
|
||||
${DC} up -d postgresql
|
||||
|
||||
# If we're running a shell, then we start up a test container with . mounted
|
||||
# to /app.
|
||||
if [ "$1" == "--shell" ]; then
|
||||
echo "Running shell..."
|
||||
|
||||
docker run \
|
||||
--rm \
|
||||
--volume "$(pwd)":/app \
|
||||
--workdir /app \
|
||||
--network pontoon_default \
|
||||
--link "${DC} ps -q postgresql" \
|
||||
--env-file ./docker/config/webapp.env \
|
||||
-e LOCAL_USER_ID=$UID \
|
||||
--tty \
|
||||
--interactive \
|
||||
local/pontoon /bin/bash "${@:2}"
|
||||
|
||||
else
|
||||
docker run \
|
||||
--rm \
|
||||
--volume "$(pwd)":/app \
|
||||
--workdir /app \
|
||||
--network pontoon_default \
|
||||
--link "${DC} ps -q postgresql" \
|
||||
--env-file ./docker/config/webapp.env \
|
||||
-e LOCAL_USER_ID=$UID \
|
||||
local/pontoon \
|
||||
/app/docker/run_tests.sh
|
||||
|
||||
echo "Done!"
|
||||
fi
|
|
@ -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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче