diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3ebc056 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*npm-debug.* \ No newline at end of file diff --git a/test-database/startup.bat b/test-database/startup.bat new file mode 100644 index 0000000..b6e3bc4 --- /dev/null +++ b/test-database/startup.bat @@ -0,0 +1,17 @@ +REM This bat file should be run only in command prompt [cmd]; will fail in PowerShell +REM Run the MySQL container, with a database named 'users' and credentials +REM for a users-service user which can access it. +echo "Starting DB..." +docker run --name db -d ^ + -e MYSQL_ROOT_PASSWORD=123 ^ + -e MYSQL_DATABASE=users -e MYSQL_USER=users_service -e MYSQL_PASSWORD=123 ^ + -p 3306:3306 ^ + mysql:latest + +REM Wait for the database service to start up. +echo "Waiting for DB to start up..." +docker exec db mysqladmin --silent --wait=50 -uusers_service -p123 ping || exit 1 + +REM Run the setup script. +echo "Setting up initial data..." +docker exec -i db mysql -uusers_service -p123 users < setup.sql \ No newline at end of file diff --git a/users-service/Dockerfile b/users-service/Dockerfile index 0d90df3..c9c26f4 100644 --- a/users-service/Dockerfile +++ b/users-service/Dockerfile @@ -1,15 +1,23 @@ # Use Node v4 as the base image. FROM node:4 -# Add everything in the current directory to our image, in the 'app' folder. -ADD . /app +# Add our user and group first to make sure their IDs get assigned consistently +RUN groupadd -r app && useradd -r -g app app -# Install dependencies -RUN cd /app; \ - npm install --production +# To reduce the build time during development we ensure non-changing layers comes first +#Creating a workdirectory +WORKDIR /app # Expose our server port. EXPOSE 8123 -# Run our app. -CMD ["node", "/app/index.js"] +# Set the default command to run when a container starts +CMD ["npm", "start"] + +# Install app dependencies +COPY package.json /app +RUN npm install --production + +# Using the recommended COPY command instead of ADD. COPY everything +# in the current directory to our image, in the 'app' folder. +COPY . /app \ No newline at end of file