Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Dockerfile to run build inside a container
Adds commands to start/rebuild/stop a Docker image of a sample Next.js app that loads the latest build of NextAuth.js from the current directory. * `npm run test:app:start` * `npm run test:app:rebuild` * `npm run test:app:stop` It is intended for further development for automated testing. ### About the build process * The Dockerfile uses a multi-stage build process to optimise build performance, but the nature of the process is slow. * Build times vary depending on computer speed and internet connection. * Inital build times are slow (it may take 10 minutes or more). * Subsequent builds on the same computer should be faster (1 minute or less). * To ensure the package.json is valid, modules required in the next-auth package.json file are re-downloaded* on every build. * A Docker compose file is used to allow us to extend the test app to run it again multiple databases. Subsequent updates may look to improve performance, but it's important checks like checking package.json is valid and running the build in isolation are performed.
- Loading branch information
1 parent
ba83685
commit f1ae26e
Showing
22 changed files
with
5,912 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Exclude directories we don't need from Docker context to improve build time | ||
node_modules | ||
www | ||
src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Multi stage build to allow us to improve performance | ||
FROM node:10-alpine as base | ||
WORKDIR /usr/src/app | ||
|
||
# Install basic dependancies (Next.js, React) | ||
COPY test/docker/app/package*.json ./ | ||
RUN npm ci | ||
|
||
FROM node:10-alpine as app | ||
COPY --from=base /usr/src/app ./ | ||
|
||
# Copy last build of library into the image and install dependences for it. | ||
# This ensures the build is valid and package.json contains everything needed | ||
# to actually run the library. | ||
# Note: You must run `npm run build` first to build a release of the library | ||
RUN mkdir -p node_modules/next-auth | ||
# Copy all entrypoints for the library (if creating a new one, add it here) | ||
COPY index.js providers.js adapters.js client.js jwt.js node_modules/next-auth/ | ||
# Copy the dist dir | ||
COPY dist node_modules/next-auth/dist | ||
# Copy the package.json for the library and install it's dependences | ||
COPY package*.json node_modules/next-auth/ | ||
RUN cd node_modules/next-auth/ && npm ci | ||
|
||
# Copy test pages across | ||
COPY test/docker/app/pages ./pages | ||
|
||
RUN npm run build | ||
|
||
CMD [ "npm", "start" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Start test app with local databases inside the container. | ||
# | ||
# Note: Uses Docker Compose v2 as v3 doesn't currently support extends. | ||
# https://docs.docker.com/compose/compose-file/compose-file-v2/ | ||
version: '2.3' | ||
|
||
services: | ||
|
||
app: | ||
build: | ||
context: ../../ | ||
dockerfile: Dockerfile | ||
ports: | ||
- "3000:3000" | ||
|
||
# mongo: | ||
# extends: | ||
# file: databases/mongo.yml | ||
# service: mongo | ||
|
||
# mssql: | ||
# extends: | ||
# file: databases/mssql.yml | ||
# service: mssql | ||
|
||
# mysql: | ||
# extends: | ||
# file: databases/mysql.yml | ||
# service: mysql | ||
|
||
# postgres: | ||
# extends: | ||
# file: databases/postgres.yml | ||
# service: postgres |
Oops, something went wrong.