Skip to content

Commit

Permalink
Fix running tests with Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvain-morin committed Feb 13, 2024
1 parent 911dd7d commit a76f3f2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 39 deletions.
23 changes: 11 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# because node-mapnik is not available in arm64
FROM --platform=linux/amd64 node:16 as base

RUN apt-get update -qq && apt-get install -y postgresql-client-11

ENV NODE_ENV=development

RUN useradd -ms /bin/bash inaturalist
Expand All @@ -17,18 +19,6 @@ COPY --chown=inaturalist:inaturalist config.docker.js config.js
# Install dependencies
RUN npm install

FROM base as test

ENV NODE_ENV=test

RUN apt-get update -qq && apt-get install -y postgresql-client-11

COPY . .

CMD [ "npm", "run", "coverage" ]

FROM base as development

# Copy app and libs
COPY --chown=inaturalist:inaturalist lib lib
COPY --chown=inaturalist:inaturalist openapi openapi
Expand All @@ -42,6 +32,15 @@ RUN mkdir /home/inaturalist/api/log
RUN mkdir /home/inaturalist/api/cache
RUN mkdir -p /home/inaturalist/api/public/uploads

FROM base as test

ENV NODE_ENV=test

COPY --chown=inaturalist:inaturalist test test

CMD [ "npm", "run", "coverage" ]

FROM base as development

EXPOSE 4000

Expand Down
3 changes: 2 additions & 1 deletion config.docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require( "fs" );

const {
NODE_ENV,
NODE_DEBUG,
INAT_DB_HOST,
INAT_DB_USER,
INAT_DB_PASS,
Expand Down Expand Up @@ -29,7 +30,7 @@ module.exports = {
jwtSecret: INAT_JWT_SECRET || "secret",
jwtApplicationSecret: INAT_JWT_APPLICATION_SECRET || "application_secret",
tileSize: 512,
debug: false,
debug: NODE_DEBUG || false,
database: {
user: INAT_DB_USER || "inaturalist",
host: INAT_DB_HOST || "127.0.0.1",
Expand Down
33 changes: 10 additions & 23 deletions config_example.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
const fs = require( "fs" );

const {
INAT_DB_HOST,
INAT_DB_USER,
INAT_DB_PASS,
INAT_ES_HOST,
INAT_REDIS_HOST,
INAT_API_URL,
INAT_RAILS_URL,
INAT_VISION_URL,
INAT_DB_SSL_KEY_PATH,
INAT_DB_SSL_CRT_PATH,
INAT_STATIC_IMAGE_URL,
INAT_JWT_SECRET,
INAT_JWT_APPLICATION_SECRET
INAT_RAILS_URL
} = process.env;
module.exports = {
// Host running the iNaturalist Rails app
apiURL: INAT_RAILS_URL ? `${INAT_RAILS_URL}` : "http://localhost:3000",
apiURL: INAT_RAILS_URL || "http://localhost:3000",
// Base URL for the current version of *this* app
currentVersionURL: INAT_API_URL ? `${INAT_API_URL}` : "http://localhost:4000/v1",
currentVersionURL: "http://localhost:4000/v1",
// Whether the Rails app supports SSL requests. For local dev assume it does not
apiHostSSL: false,
writeHostSSL: false,
Expand All @@ -37,33 +28,29 @@ module.exports = {
geometry_field: "geom",
srid: 4326,
password: INAT_DB_PASS || "inaturalist",
ssl: ( INAT_DB_SSL_KEY_PATH && INAT_DB_SSL_CRT_PATH ) ? {
rejectUnauthorized: false,
key: fs.readFileSync( INAT_DB_SSL_KEY_PATH ),
cert: fs.readFileSync( INAT_DB_SSL_CRT_PATH )
} : false
ssl: false
},
tileSize: 512,
debug: true,
logLevel: "info", // only "debug" does anything right now
websiteURL: INAT_RAILS_URL ? `${INAT_RAILS_URL}` : "http://localhost:3000/",
staticImagePrefix: INAT_STATIC_IMAGE_URL ? `${INAT_STATIC_IMAGE_URL}` : "http://localhost:3000/attachments/",
websiteURL: "http://localhost:3000/",
staticImagePrefix: "http://localhost:3000/attachments/",
userImagePrefix: "/attachments/users/icons/",
jwtSecret: INAT_JWT_SECRET ? `${INAT_JWT_SECRET}` : "secret",
jwtApplicationSecret: INAT_JWT_APPLICATION_SECRET ? `${INAT_JWT_APPLICATION_SECRET}` : "application_secret",
jwtSecret: "secret",
jwtApplicationSecret: "application_secret",
imageProcesing: {
// Path to a file listing the taxonomy used in the computer vision model
taxaFilePath: "",
// Path to a directory where uploads should be stored. /tmp/ is fine on most
// *nix systems
uploadsDir: "/tmp/",
// Base URL for the web app returning computer vision results
tensorappURL: INAT_VISION_URL ? `${INAT_VISION_URL}` : "http://localhost:6006"
tensorappURL: "http://localhost:6006"
},
redis: {
host: INAT_REDIS_HOST || "127.0.0.1",
port: 6379
}
// Simulate maintance by returning 503 for all requests
// maintenanceUntil: "Sat, 23 Sep 2023 7:00:00 GMT"
};
};

Check failure on line 56 in config_example.js

View workflow job for this annotation

GitHub Actions / build-and-test / Build/Test

Newline required at end of file but not found

Check failure on line 56 in config_example.js

View workflow job for this annotation

GitHub Actions / build-and-test / Build/Test

Newline required at end of file but not found
5 changes: 2 additions & 3 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ services:
target: test
environment:
NODE_ENV: test
NODE_DEBUG: true
INAT_DB_HOST: pg
INAT_DB_USER : 'inaturalist'
INAT_DB_PASS: 'inaturalist'
INAT_ES_HOST: es
INAT_REDIS_HOST: redis
INAT_WEB_HOST: host.docker.internal
INAT_RAILS_URL: http://localhost:3000
INAT_DB_NAME: inaturalist_test
INAT_ES_INDEX_PREFIX: test
ports:
- 4000:4000
extra_hosts:
- "host.docker.internal:host-gateway"

volumes:
redis_data_test:
Expand Down

0 comments on commit a76f3f2

Please sign in to comment.