From 49fd40ca4abe0f8ab1ff4797b2c56afddca23018 Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Wed, 12 Jun 2024 19:02:27 +0200 Subject: [PATCH 01/13] Add build info --- .github/workflows/CICD-dev.yml | 5 +++++ .github/workflows/CICD-main.yml | 5 +++++ Dockerfile | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/.github/workflows/CICD-dev.yml b/.github/workflows/CICD-dev.yml index 384bd184..1f9d6d7d 100644 --- a/.github/workflows/CICD-dev.yml +++ b/.github/workflows/CICD-dev.yml @@ -37,6 +37,11 @@ jobs: file: ./Dockerfile push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:${{ github.ref_name }} + build-args: | + GIT_BRANCH=${{ github.ref_name }} + GIT_COMMIT=${{ github.sha }} + IMAGE_TAG=${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:${{ github.ref_name }} + BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") refresh-dev-staging-deployment: name: Refresh Dev Staging Deployment diff --git a/.github/workflows/CICD-main.yml b/.github/workflows/CICD-main.yml index 3e7284da..1f0b6a6b 100644 --- a/.github/workflows/CICD-main.yml +++ b/.github/workflows/CICD-main.yml @@ -38,6 +38,11 @@ jobs: tags: | ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:latest + build-args: | + GIT_BRANCH=${{ github.ref_name }} + GIT_COMMIT=${{ github.sha }} + IMAGE_TAG=${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:latest + BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") refresh-main-staging-deployment: name: Refresh Main Staging Deployment diff --git a/Dockerfile b/Dockerfile index 388c8748..79228273 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,21 @@ RUN mkdir /home/inaturalist/api/log RUN mkdir /home/inaturalist/api/cache RUN mkdir -p /home/inaturalist/api/public/uploads +ARG GIT_BRANCH +ARG GIT_COMMIT +ARG IMAGE_TAG +ARG BUILD_DATE + +ENV GIT_BRANCH=${GIT_BRANCH} +ENV GIT_COMMIT=${GIT_COMMIT} +ENV IMAGE_TAG=${IMAGE_TAG} +ENV BUILD_DATE=${BUILD_DATE} + +RUN echo "GIT_BRANCH=${GIT_BRANCH}" >> /home/inaturalist/api/build_info +RUN echo "GIT_COMMIT=${GIT_COMMIT}" >> /home/inaturalist/api/build_info +RUN echo "IMAGE_TAG=${IMAGE_TAG}" > /home/inaturalist/api/build_info +RUN echo "BUILD_DATE=${BUILD_DATE}" >> /home/inaturalist/api/build_info + FROM base as test ENV NODE_ENV=test From e10f748f56d5511e867b488d1ae43c91a1bab3ed Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Thu, 13 Jun 2024 10:06:32 +0200 Subject: [PATCH 02/13] Add build info --- .github/workflows/CICD-main.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CICD-main.yml b/.github/workflows/CICD-main.yml index 1f0b6a6b..1a05c314 100644 --- a/.github/workflows/CICD-main.yml +++ b/.github/workflows/CICD-main.yml @@ -29,6 +29,9 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Set build date + run: echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" + - name: Build/Push Main inaturalistapi uses: docker/build-push-action@v5 with: @@ -42,7 +45,7 @@ jobs: GIT_BRANCH=${{ github.ref_name }} GIT_COMMIT=${{ github.sha }} IMAGE_TAG=${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:latest - BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + BUILD_DATE=${{ env.BUILD_DATE }} refresh-main-staging-deployment: name: Refresh Main Staging Deployment From 264825a5a5a6ddfb81bd12eb70e545df8e320424 Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Thu, 13 Jun 2024 10:08:23 +0200 Subject: [PATCH 03/13] Add build info --- .github/workflows/CICD-dev.yml | 9 ++++++--- .github/workflows/CICD-main.yml | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CICD-dev.yml b/.github/workflows/CICD-dev.yml index 1f9d6d7d..ed2a33a8 100644 --- a/.github/workflows/CICD-dev.yml +++ b/.github/workflows/CICD-dev.yml @@ -26,10 +26,13 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - + + - name: Set build date + run: echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" + - name: Build/Push Dev inaturalistapi uses: docker/build-push-action@v5 with: @@ -41,7 +44,7 @@ jobs: GIT_BRANCH=${{ github.ref_name }} GIT_COMMIT=${{ github.sha }} IMAGE_TAG=${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:${{ github.ref_name }} - BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + BUILD_DATE=${{ env.BUILD_DATE }} refresh-dev-staging-deployment: name: Refresh Dev Staging Deployment diff --git a/.github/workflows/CICD-main.yml b/.github/workflows/CICD-main.yml index 1a05c314..c855077f 100644 --- a/.github/workflows/CICD-main.yml +++ b/.github/workflows/CICD-main.yml @@ -28,7 +28,7 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - + - name: Set build date run: echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" From eb67946232c81140e2ee313a27c7e7f9d5540f01 Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Thu, 13 Jun 2024 10:43:06 +0200 Subject: [PATCH 04/13] Add build info --- .github/workflows/CICD-dev.yml | 2 +- .github/workflows/CICD-main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CICD-dev.yml b/.github/workflows/CICD-dev.yml index ed2a33a8..1df41b7a 100644 --- a/.github/workflows/CICD-dev.yml +++ b/.github/workflows/CICD-dev.yml @@ -31,7 +31,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Set build date - run: echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" + run: echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV - name: Build/Push Dev inaturalistapi uses: docker/build-push-action@v5 diff --git a/.github/workflows/CICD-main.yml b/.github/workflows/CICD-main.yml index c855077f..6ee346e4 100644 --- a/.github/workflows/CICD-main.yml +++ b/.github/workflows/CICD-main.yml @@ -30,7 +30,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Set build date - run: echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" + run: echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV - name: Build/Push Main inaturalistapi uses: docker/build-push-action@v5 From 804ff0838886faa550a6c3de8beb2c167c0a50d0 Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Thu, 13 Jun 2024 10:50:29 +0200 Subject: [PATCH 05/13] Add build info --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 79228273..8666f457 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,9 +42,9 @@ ENV GIT_COMMIT=${GIT_COMMIT} ENV IMAGE_TAG=${IMAGE_TAG} ENV BUILD_DATE=${BUILD_DATE} -RUN echo "GIT_BRANCH=${GIT_BRANCH}" >> /home/inaturalist/api/build_info +RUN echo "GIT_BRANCH=${GIT_BRANCH}" > /home/inaturalist/api/build_info RUN echo "GIT_COMMIT=${GIT_COMMIT}" >> /home/inaturalist/api/build_info -RUN echo "IMAGE_TAG=${IMAGE_TAG}" > /home/inaturalist/api/build_info +RUN echo "IMAGE_TAG=${IMAGE_TAG}" >> /home/inaturalist/api/build_info RUN echo "BUILD_DATE=${BUILD_DATE}" >> /home/inaturalist/api/build_info FROM base as test From 4e35684adf4ff776611dfa15ddedb78f9bcf1945 Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Thu, 13 Jun 2024 17:06:20 +0200 Subject: [PATCH 06/13] Display build info endpoint --- config.docker.js | 6 ++-- lib/controllers/v2/build_info_controller.js | 19 ++++++++++++ lib/util.js | 10 ++++++ openapi/paths/v2/build_info.js | 34 +++++++++++++++++++++ openapi/schema/request/build_info.js | 3 ++ openapi/schema/response/build_info.js | 8 +++++ package-lock.json | 17 +++++++++++ package.json | 1 + 8 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 lib/controllers/v2/build_info_controller.js create mode 100644 openapi/paths/v2/build_info.js create mode 100644 openapi/schema/request/build_info.js create mode 100644 openapi/schema/response/build_info.js diff --git a/config.docker.js b/config.docker.js index 1b805709..c4438a77 100644 --- a/config.docker.js +++ b/config.docker.js @@ -21,7 +21,8 @@ const { INAT_AWS_OPENDATA_REGION, INAT_AWS_OPENDATA_ACL, INAT_TAXA_FILE_PATH, - INAT_SEEK_EXCEPTION_LIST_ID + INAT_SEEK_EXCEPTION_LIST_ID, + INAT_INTERNAL_IP_RANGES } = process.env; module.exports = { @@ -69,5 +70,6 @@ module.exports = { host: INAT_ES_HOST ? `http://${INAT_ES_HOST}:9200` : "http://localhost:9200" }, cacheDir: "/home/inaturalist/api/cache", - seekExceptionListID: INAT_SEEK_EXCEPTION_LIST_ID || 0 + seekExceptionListID: INAT_SEEK_EXCEPTION_LIST_ID || 0, + internalIPs: INAT_INTERNAL_IP_RANGES || "" }; diff --git a/lib/controllers/v2/build_info_controller.js b/lib/controllers/v2/build_info_controller.js new file mode 100644 index 00000000..b4f479ae --- /dev/null +++ b/lib/controllers/v2/build_info_controller.js @@ -0,0 +1,19 @@ +const process = require( "process" ); +const util = require( "../../util" ); + +const index = async req => { + if ( !util.isInternalRequest( req ) ) { + throw util.httpError( 401, "Unauthorized" ); + } + const buildInfoJSON = { + git_branch: process.env.GIT_BRANCH, + git_commit: process.env.GIT_COMMIT, + image_tag: process.env.IMAGE_TAG, + build_date: process.env.BUILD_DATE + }; + return buildInfoJSON; +}; + +module.exports = { + index +}; diff --git a/lib/util.js b/lib/util.js index 72a32034..84db5155 100644 --- a/lib/util.js +++ b/lib/util.js @@ -2,6 +2,7 @@ const _ = require( "lodash" ); const moment = require( "moment" ); const md5 = require( "md5" ); +const ipRangeCheck = require( "ip-range-check" ); const config = require( "../config" ); const Logstasher = require( "./logstasher" ); @@ -502,6 +503,15 @@ const util = class util { return true; } + static isInternalRequest( req ) { + const internalIPs = config.internalIPs || ""; + const allowedRanges = internalIPs.split( "," ); + const clientIp = req.headers["x-forwarded-for"] || req.connection.remoteAddress; + console.log( "### internalIPs = " + allowedRanges ); + console.log( "### clientIp = " + clientIp ); + return allowedRanges.some( range => ipRangeCheck( clientIp, range ) ); + } + // Utility to look up IDs from UUIDs to forward requests to the v1 API static async uuidsToSerialIds( req, model ) { // eslint-disable-next-line global-require diff --git a/openapi/paths/v2/build_info.js b/openapi/paths/v2/build_info.js new file mode 100644 index 00000000..a56f5388 --- /dev/null +++ b/openapi/paths/v2/build_info.js @@ -0,0 +1,34 @@ +const j2s = require( "joi-to-swagger" ); +const BuildInfoController = require( "../../../lib/controllers/v2/build_info_controller" ); + +module.exports = sendWrapper => { + async function GET( req, res ) { + const results = await BuildInfoController.index( req ); + sendWrapper( req, res, null, results ); + } + + GET.apiDoc = { + tags: ["BuildInfo"], + summary: "Display build information", + responses: { + 200: { + description: "Build information", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/BuildInfo" + } + } + } + }, + default: { + $ref: "#/components/responses/Error" + } + }, + "x-unpublished": true + }; + + return { + GET + }; +}; diff --git a/openapi/schema/request/build_info.js b/openapi/schema/request/build_info.js new file mode 100644 index 00000000..c79897cb --- /dev/null +++ b/openapi/schema/request/build_info.js @@ -0,0 +1,3 @@ +const Joi = require( "joi" ); + +module.exports = Joi.object( ).keys( {} ); diff --git a/openapi/schema/response/build_info.js b/openapi/schema/response/build_info.js new file mode 100644 index 00000000..02438d5b --- /dev/null +++ b/openapi/schema/response/build_info.js @@ -0,0 +1,8 @@ +const Joi = require( "joi" ); + +module.exports = Joi.object( ).keys( { + git_branch: Joi.string( ), + git_commit: Joi.string( ), + image_tag: Joi.string( ), + build_date: Joi.string( ) +} ).unknown( false ); diff --git a/package-lock.json b/package-lock.json index 3221f46e..92db5282 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "handlebars": "^4.7.7", "inaturalistjs": "github:inaturalist/inaturalistjs", "intl": "^1.2.5", + "ip-range-check": "^0.2.0", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", "js-yaml": "^4.1.0", @@ -7076,6 +7077,14 @@ "node": ">= 0.10" } }, + "node_modules/ip-range-check": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/ip-range-check/-/ip-range-check-0.2.0.tgz", + "integrity": "sha512-oaM3l/3gHbLlt/tCWLvt0mj1qUaI+STuRFnUvARGCujK9vvU61+2JsDpmkMzR4VsJhuFXWWgeKKVnwwoFfzCqw==", + "dependencies": { + "ipaddr.js": "^1.0.1" + } + }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", @@ -16963,6 +16972,14 @@ "sprintf-js": "1.1.2" } }, + "ip-range-check": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/ip-range-check/-/ip-range-check-0.2.0.tgz", + "integrity": "sha512-oaM3l/3gHbLlt/tCWLvt0mj1qUaI+STuRFnUvARGCujK9vvU61+2JsDpmkMzR4VsJhuFXWWgeKKVnwwoFfzCqw==", + "requires": { + "ipaddr.js": "^1.0.1" + } + }, "ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", diff --git a/package.json b/package.json index 3c7d7cea..5e8c1a03 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "handlebars": "^4.7.7", "inaturalistjs": "github:inaturalist/inaturalistjs", "intl": "^1.2.5", + "ip-range-check": "^0.2.0", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", "js-yaml": "^4.1.0", From 7410c1dc71af63a8ff9aa0d82f551a4e6b5b86a8 Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Wed, 19 Jun 2024 18:41:27 +0200 Subject: [PATCH 07/13] Display build info endpoint --- config.docker.js | 6 +-- .../v2/app_build_info_controller.js | 43 +++++++++++++++++++ lib/controllers/v2/build_info_controller.js | 2 +- lib/util.js | 10 ----- openapi/paths/v2/app_build_info.js | 36 ++++++++++++++++ openapi/paths/v2/build_info.js | 4 +- openapi/schema/request/app_build_info.js | 3 ++ openapi/schema/response/app_build_info.js | 22 ++++++++++ package-lock.json | 17 -------- package.json | 3 +- 10 files changed, 111 insertions(+), 35 deletions(-) create mode 100644 lib/controllers/v2/app_build_info_controller.js create mode 100644 openapi/paths/v2/app_build_info.js create mode 100644 openapi/schema/request/app_build_info.js create mode 100644 openapi/schema/response/app_build_info.js diff --git a/config.docker.js b/config.docker.js index c4438a77..1b805709 100644 --- a/config.docker.js +++ b/config.docker.js @@ -21,8 +21,7 @@ const { INAT_AWS_OPENDATA_REGION, INAT_AWS_OPENDATA_ACL, INAT_TAXA_FILE_PATH, - INAT_SEEK_EXCEPTION_LIST_ID, - INAT_INTERNAL_IP_RANGES + INAT_SEEK_EXCEPTION_LIST_ID } = process.env; module.exports = { @@ -70,6 +69,5 @@ module.exports = { host: INAT_ES_HOST ? `http://${INAT_ES_HOST}:9200` : "http://localhost:9200" }, cacheDir: "/home/inaturalist/api/cache", - seekExceptionListID: INAT_SEEK_EXCEPTION_LIST_ID || 0, - internalIPs: INAT_INTERNAL_IP_RANGES || "" + seekExceptionListID: INAT_SEEK_EXCEPTION_LIST_ID || 0 }; diff --git a/lib/controllers/v2/app_build_info_controller.js b/lib/controllers/v2/app_build_info_controller.js new file mode 100644 index 00000000..aa8d6e78 --- /dev/null +++ b/lib/controllers/v2/app_build_info_controller.js @@ -0,0 +1,43 @@ +const { build_info } = require( "inaturalistjs" ); +const process = require( "process" ); +const fetch = require( "node-fetch" ); +const InaturalistAPI = require( "../../inaturalist_api" ); +const util = require( "../../util" ); +const config = require( "../../../config" ); + +const index = async req => { + if ( !req.userSession || ( req.userSession && !req.userSession.isAdmin ) ) { + throw util.httpError( 401, "Unauthorized" ); + } + // Get Rails Build Info + const railsBuildInfoJSON = await InaturalistAPI.iNatJSWrap( build_info.get, req ); + // Get API Build Info + const apiBuildInfoJSON = { + git_branch: process.env.GIT_BRANCH, + git_commit: process.env.GIT_COMMIT, + image_tag: process.env.IMAGE_TAG, + build_date: process.env.BUILD_DATE + }; + // Get Vision Build Info + let visionBuildInfoJSON = {}; + try { + const response = await fetch( `${config.imageProcesing.tensorappURL}/build_info` ); + if ( !response.ok ) { + throw util.httpError( 500, "Error" ); + } + visionBuildInfoJSON = await response.json( ); + } catch ( error ) { + throw util.httpError( 500, "Error" ); + } + // Application Build Info + const appBuildInfoJSON = { + rails: railsBuildInfoJSON, + api: apiBuildInfoJSON, + vision: visionBuildInfoJSON + }; + return appBuildInfoJSON; +}; + +module.exports = { + index +}; diff --git a/lib/controllers/v2/build_info_controller.js b/lib/controllers/v2/build_info_controller.js index b4f479ae..283fdc6f 100644 --- a/lib/controllers/v2/build_info_controller.js +++ b/lib/controllers/v2/build_info_controller.js @@ -2,7 +2,7 @@ const process = require( "process" ); const util = require( "../../util" ); const index = async req => { - if ( !util.isInternalRequest( req ) ) { + if ( !req.userSession || ( req.userSession && !req.userSession.isAdmin ) ) { throw util.httpError( 401, "Unauthorized" ); } const buildInfoJSON = { diff --git a/lib/util.js b/lib/util.js index 84db5155..72a32034 100644 --- a/lib/util.js +++ b/lib/util.js @@ -2,7 +2,6 @@ const _ = require( "lodash" ); const moment = require( "moment" ); const md5 = require( "md5" ); -const ipRangeCheck = require( "ip-range-check" ); const config = require( "../config" ); const Logstasher = require( "./logstasher" ); @@ -503,15 +502,6 @@ const util = class util { return true; } - static isInternalRequest( req ) { - const internalIPs = config.internalIPs || ""; - const allowedRanges = internalIPs.split( "," ); - const clientIp = req.headers["x-forwarded-for"] || req.connection.remoteAddress; - console.log( "### internalIPs = " + allowedRanges ); - console.log( "### clientIp = " + clientIp ); - return allowedRanges.some( range => ipRangeCheck( clientIp, range ) ); - } - // Utility to look up IDs from UUIDs to forward requests to the v1 API static async uuidsToSerialIds( req, model ) { // eslint-disable-next-line global-require diff --git a/openapi/paths/v2/app_build_info.js b/openapi/paths/v2/app_build_info.js new file mode 100644 index 00000000..ba8421e0 --- /dev/null +++ b/openapi/paths/v2/app_build_info.js @@ -0,0 +1,36 @@ +const AppBuildInfoController = require( "../../../lib/controllers/v2/app_build_info_controller" ); + +module.exports = sendWrapper => { + async function GET( req, res ) { + const results = await AppBuildInfoController.index( req ); + sendWrapper( req, res, null, results ); + } + + GET.apiDoc = { + tags: ["AppBuildInfo"], + summary: "Display application build information", + security: [{ + userJwtRequired: [] + }], + responses: { + 200: { + description: "Application build information", + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/AppBuildInfo" + } + } + } + }, + default: { + $ref: "#/components/responses/Error" + } + }, + "x-unpublished": true + }; + + return { + GET + }; +}; diff --git a/openapi/paths/v2/build_info.js b/openapi/paths/v2/build_info.js index a56f5388..7efe8249 100644 --- a/openapi/paths/v2/build_info.js +++ b/openapi/paths/v2/build_info.js @@ -1,4 +1,3 @@ -const j2s = require( "joi-to-swagger" ); const BuildInfoController = require( "../../../lib/controllers/v2/build_info_controller" ); module.exports = sendWrapper => { @@ -10,6 +9,9 @@ module.exports = sendWrapper => { GET.apiDoc = { tags: ["BuildInfo"], summary: "Display build information", + security: [{ + userJwtRequired: [] + }], responses: { 200: { description: "Build information", diff --git a/openapi/schema/request/app_build_info.js b/openapi/schema/request/app_build_info.js new file mode 100644 index 00000000..c79897cb --- /dev/null +++ b/openapi/schema/request/app_build_info.js @@ -0,0 +1,3 @@ +const Joi = require( "joi" ); + +module.exports = Joi.object( ).keys( {} ); diff --git a/openapi/schema/response/app_build_info.js b/openapi/schema/response/app_build_info.js new file mode 100644 index 00000000..87484938 --- /dev/null +++ b/openapi/schema/response/app_build_info.js @@ -0,0 +1,22 @@ +const Joi = require( "joi" ); + +module.exports = Joi.object( ).keys( { + rails: Joi.object( ).keys( { + git_branch: Joi.string( ), + git_commit: Joi.string( ), + image_tag: Joi.string( ), + build_date: Joi.string( ) + } ), + api: Joi.object( ).keys( { + git_branch: Joi.string( ), + git_commit: Joi.string( ), + image_tag: Joi.string( ), + build_date: Joi.string( ) + } ), + vision: Joi.object( ).keys( { + git_branch: Joi.string( ), + git_commit: Joi.string( ), + image_tag: Joi.string( ), + build_date: Joi.string( ) + } ) +} ).unknown( false ); diff --git a/package-lock.json b/package-lock.json index 92db5282..3221f46e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,7 +34,6 @@ "handlebars": "^4.7.7", "inaturalistjs": "github:inaturalist/inaturalistjs", "intl": "^1.2.5", - "ip-range-check": "^0.2.0", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", "js-yaml": "^4.1.0", @@ -7077,14 +7076,6 @@ "node": ">= 0.10" } }, - "node_modules/ip-range-check": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/ip-range-check/-/ip-range-check-0.2.0.tgz", - "integrity": "sha512-oaM3l/3gHbLlt/tCWLvt0mj1qUaI+STuRFnUvARGCujK9vvU61+2JsDpmkMzR4VsJhuFXWWgeKKVnwwoFfzCqw==", - "dependencies": { - "ipaddr.js": "^1.0.1" - } - }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", @@ -16972,14 +16963,6 @@ "sprintf-js": "1.1.2" } }, - "ip-range-check": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/ip-range-check/-/ip-range-check-0.2.0.tgz", - "integrity": "sha512-oaM3l/3gHbLlt/tCWLvt0mj1qUaI+STuRFnUvARGCujK9vvU61+2JsDpmkMzR4VsJhuFXWWgeKKVnwwoFfzCqw==", - "requires": { - "ipaddr.js": "^1.0.1" - } - }, "ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", diff --git a/package.json b/package.json index 5e8c1a03..30236c45 100644 --- a/package.json +++ b/package.json @@ -41,9 +41,8 @@ "geoip-lite": "^1.4.3", "h3-js": "^4.1.0", "handlebars": "^4.7.7", - "inaturalistjs": "github:inaturalist/inaturalistjs", + "inaturalistjs": "github:inaturalist/inaturalistjs#0828cb8fb22736ffe78b737edea793405a158ce8", "intl": "^1.2.5", - "ip-range-check": "^0.2.0", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", "js-yaml": "^4.1.0", From 93f4d9e074fdb88e9a5c153245e4b04e6af97986 Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Wed, 19 Jun 2024 18:43:08 +0200 Subject: [PATCH 08/13] Display build info endpoint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 30236c45..3c7d7cea 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "geoip-lite": "^1.4.3", "h3-js": "^4.1.0", "handlebars": "^4.7.7", - "inaturalistjs": "github:inaturalist/inaturalistjs#0828cb8fb22736ffe78b737edea793405a158ce8", + "inaturalistjs": "github:inaturalist/inaturalistjs", "intl": "^1.2.5", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", From 94d4a74c4fba0a9d1e553cf9878f4c846fe0632f Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Thu, 20 Jun 2024 22:16:09 +0200 Subject: [PATCH 09/13] Display build info endpoint --- lib/controllers/v2/app_build_info_controller.js | 2 ++ package-lock.json | 12 +++++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/controllers/v2/app_build_info_controller.js b/lib/controllers/v2/app_build_info_controller.js index aa8d6e78..a5fa7be8 100644 --- a/lib/controllers/v2/app_build_info_controller.js +++ b/lib/controllers/v2/app_build_info_controller.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line camelcase const { build_info } = require( "inaturalistjs" ); const process = require( "process" ); const fetch = require( "node-fetch" ); @@ -10,6 +11,7 @@ const index = async req => { throw util.httpError( 401, "Unauthorized" ); } // Get Rails Build Info + // eslint-disable-next-line camelcase const railsBuildInfoJSON = await InaturalistAPI.iNatJSWrap( build_info.get, req ); // Get API Build Info const apiBuildInfoJSON = { diff --git a/package-lock.json b/package-lock.json index 3221f46e..0445bf47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "geoip-lite": "^1.4.3", "h3-js": "^4.1.0", "handlebars": "^4.7.7", - "inaturalistjs": "github:inaturalist/inaturalistjs", + "inaturalistjs": "github:inaturalist/inaturalistjs#0828cb8fb22736ffe78b737edea793405a158ce8", "intl": "^1.2.5", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", @@ -7012,8 +7012,9 @@ } }, "node_modules/inaturalistjs": { - "version": "2.10.0", - "resolved": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#2467869999fc2eee64eb928b7798ea50a9553ea2", + "version": "2.12.0", + "resolved": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#0828cb8fb22736ffe78b737edea793405a158ce8", + "integrity": "sha512-0Degd6YhzSMCcj8DtFMNi3rIoukwGbRwhbqlBXmih9TsL5RZ4oxLOqHRaetcvtcDrvhG+iof0fcFC2sxkh6LmQ==", "license": "MIT", "dependencies": { "cross-fetch": "^3.1.5", @@ -16909,8 +16910,9 @@ "dev": true }, "inaturalistjs": { - "version": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#2467869999fc2eee64eb928b7798ea50a9553ea2", - "from": "inaturalistjs@github:inaturalist/inaturalistjs", + "version": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#0828cb8fb22736ffe78b737edea793405a158ce8", + "integrity": "sha512-0Degd6YhzSMCcj8DtFMNi3rIoukwGbRwhbqlBXmih9TsL5RZ4oxLOqHRaetcvtcDrvhG+iof0fcFC2sxkh6LmQ==", + "from": "inaturalistjs@github:inaturalist/inaturalistjs#0828cb8fb22736ffe78b737edea793405a158ce8", "requires": { "cross-fetch": "^3.1.5", "form-data": "^4.0.0", diff --git a/package.json b/package.json index 3c7d7cea..30236c45 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "geoip-lite": "^1.4.3", "h3-js": "^4.1.0", "handlebars": "^4.7.7", - "inaturalistjs": "github:inaturalist/inaturalistjs", + "inaturalistjs": "github:inaturalist/inaturalistjs#0828cb8fb22736ffe78b737edea793405a158ce8", "intl": "^1.2.5", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", From 693d13c165b9328dc2f80f0b4cd0c0c37490e1bc Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Fri, 28 Jun 2024 18:33:33 +0200 Subject: [PATCH 10/13] Add build info --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5a942c40..15d18821 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "geoip-lite": "^1.4.3", "h3-js": "^4.1.0", "handlebars": "^4.7.7", - "inaturalistjs": "github:inaturalist/inaturalistjs#0828cb8fb22736ffe78b737edea793405a158ce8", + "inaturalistjs": "github:inaturalist/inaturalistjs#b4bc2070f66ee700ab95034e7ce76b6829b4a4d5", "intl": "^1.2.5", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", @@ -7022,8 +7022,8 @@ }, "node_modules/inaturalistjs": { "version": "2.12.0", - "resolved": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#0828cb8fb22736ffe78b737edea793405a158ce8", - "integrity": "sha512-0Degd6YhzSMCcj8DtFMNi3rIoukwGbRwhbqlBXmih9TsL5RZ4oxLOqHRaetcvtcDrvhG+iof0fcFC2sxkh6LmQ==", + "resolved": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#b4bc2070f66ee700ab95034e7ce76b6829b4a4d5", + "integrity": "sha512-MbkiQ4RYkb9aBMMe2uy9xD44HsXFJmSu9H486mr7LAmd/zF26afCC815u0f3OaFABTv+wm7yEPF/Q15/2WODdw==", "license": "MIT", "dependencies": { "cross-fetch": "^3.1.5", @@ -16924,9 +16924,9 @@ "dev": true }, "inaturalistjs": { - "version": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#0828cb8fb22736ffe78b737edea793405a158ce8", - "integrity": "sha512-0Degd6YhzSMCcj8DtFMNi3rIoukwGbRwhbqlBXmih9TsL5RZ4oxLOqHRaetcvtcDrvhG+iof0fcFC2sxkh6LmQ==", - "from": "inaturalistjs@github:inaturalist/inaturalistjs#0828cb8fb22736ffe78b737edea793405a158ce8", + "version": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#b4bc2070f66ee700ab95034e7ce76b6829b4a4d5", + "integrity": "sha512-MbkiQ4RYkb9aBMMe2uy9xD44HsXFJmSu9H486mr7LAmd/zF26afCC815u0f3OaFABTv+wm7yEPF/Q15/2WODdw==", + "from": "inaturalistjs@github:inaturalist/inaturalistjs#b4bc2070f66ee700ab95034e7ce76b6829b4a4d5", "requires": { "cross-fetch": "^3.1.5", "form-data": "^4.0.0", diff --git a/package.json b/package.json index 30236c45..6f93a5a5 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "geoip-lite": "^1.4.3", "h3-js": "^4.1.0", "handlebars": "^4.7.7", - "inaturalistjs": "github:inaturalist/inaturalistjs#0828cb8fb22736ffe78b737edea793405a158ce8", + "inaturalistjs": "github:inaturalist/inaturalistjs#b4bc2070f66ee700ab95034e7ce76b6829b4a4d5", "intl": "^1.2.5", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", From 94f656c398eb9a96d2e2365621cab052348d368b Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Fri, 28 Jun 2024 18:59:42 +0200 Subject: [PATCH 11/13] Add build info --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 15d18821..1ba7d812 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "geoip-lite": "^1.4.3", "h3-js": "^4.1.0", "handlebars": "^4.7.7", - "inaturalistjs": "github:inaturalist/inaturalistjs#b4bc2070f66ee700ab95034e7ce76b6829b4a4d5", + "inaturalistjs": "github:inaturalist/inaturalistjs#2fc60fb0870f35427c225b73745a5c492b41637a", "intl": "^1.2.5", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", @@ -7022,8 +7022,8 @@ }, "node_modules/inaturalistjs": { "version": "2.12.0", - "resolved": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#b4bc2070f66ee700ab95034e7ce76b6829b4a4d5", - "integrity": "sha512-MbkiQ4RYkb9aBMMe2uy9xD44HsXFJmSu9H486mr7LAmd/zF26afCC815u0f3OaFABTv+wm7yEPF/Q15/2WODdw==", + "resolved": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#2fc60fb0870f35427c225b73745a5c492b41637a", + "integrity": "sha512-0Degd6YhzSMCcj8DtFMNi3rIoukwGbRwhbqlBXmih9TsL5RZ4oxLOqHRaetcvtcDrvhG+iof0fcFC2sxkh6LmQ==", "license": "MIT", "dependencies": { "cross-fetch": "^3.1.5", @@ -16924,9 +16924,9 @@ "dev": true }, "inaturalistjs": { - "version": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#b4bc2070f66ee700ab95034e7ce76b6829b4a4d5", - "integrity": "sha512-MbkiQ4RYkb9aBMMe2uy9xD44HsXFJmSu9H486mr7LAmd/zF26afCC815u0f3OaFABTv+wm7yEPF/Q15/2WODdw==", - "from": "inaturalistjs@github:inaturalist/inaturalistjs#b4bc2070f66ee700ab95034e7ce76b6829b4a4d5", + "version": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#2fc60fb0870f35427c225b73745a5c492b41637a", + "integrity": "sha512-0Degd6YhzSMCcj8DtFMNi3rIoukwGbRwhbqlBXmih9TsL5RZ4oxLOqHRaetcvtcDrvhG+iof0fcFC2sxkh6LmQ==", + "from": "inaturalistjs@github:inaturalist/inaturalistjs#2fc60fb0870f35427c225b73745a5c492b41637a", "requires": { "cross-fetch": "^3.1.5", "form-data": "^4.0.0", diff --git a/package.json b/package.json index 6f93a5a5..0e2d5e5a 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "geoip-lite": "^1.4.3", "h3-js": "^4.1.0", "handlebars": "^4.7.7", - "inaturalistjs": "github:inaturalist/inaturalistjs#b4bc2070f66ee700ab95034e7ce76b6829b4a4d5", + "inaturalistjs": "github:inaturalist/inaturalistjs#2fc60fb0870f35427c225b73745a5c492b41637a", "intl": "^1.2.5", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", From 9fdb3de8c4f6c8ca04c51813b8393df43a714456 Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Mon, 1 Jul 2024 10:06:41 +0200 Subject: [PATCH 12/13] Add build info --- .github/workflows/CICD-dev.yml | 7 ++++++- .github/workflows/CICD-main.yml | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CICD-dev.yml b/.github/workflows/CICD-dev.yml index adaef930..c9233955 100644 --- a/.github/workflows/CICD-dev.yml +++ b/.github/workflows/CICD-dev.yml @@ -53,7 +53,12 @@ jobs: file: ./Dockerfile-cleanup push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi-cleanup:${{ github.ref_name }} - + build-args: | + GIT_BRANCH=${{ github.ref_name }} + GIT_COMMIT=${{ github.sha }} + IMAGE_TAG=${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi-cleanup:${{ github.ref_name }} + BUILD_DATE=${{ env.BUILD_DATE }} + refresh-dev-staging-deployment: name: Refresh Dev Staging Deployment needs: build-and-push-dev-docker-image diff --git a/.github/workflows/CICD-main.yml b/.github/workflows/CICD-main.yml index 0c28b42a..415c77e1 100644 --- a/.github/workflows/CICD-main.yml +++ b/.github/workflows/CICD-main.yml @@ -56,7 +56,12 @@ jobs: tags: | ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi-cleanup:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi-cleanup:latest - + build-args: | + GIT_BRANCH=${{ github.ref_name }} + GIT_COMMIT=${{ github.sha }} + IMAGE_TAG=${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi-cleanup:latest + BUILD_DATE=${{ env.BUILD_DATE }} + refresh-main-staging-deployment: name: Refresh Main Staging Deployment needs: build-and-push-main-docker-image From 18fbb347b1268dc01690f138b52046ed34c44a9c Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Wed, 3 Jul 2024 10:16:46 +0200 Subject: [PATCH 13/13] Add build info --- lib/controllers/v2/app_build_info_controller.js | 8 ++++---- lib/controllers/v2/build_info_controller.js | 8 ++++---- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/controllers/v2/app_build_info_controller.js b/lib/controllers/v2/app_build_info_controller.js index a5fa7be8..eeff3eae 100644 --- a/lib/controllers/v2/app_build_info_controller.js +++ b/lib/controllers/v2/app_build_info_controller.js @@ -15,10 +15,10 @@ const index = async req => { const railsBuildInfoJSON = await InaturalistAPI.iNatJSWrap( build_info.get, req ); // Get API Build Info const apiBuildInfoJSON = { - git_branch: process.env.GIT_BRANCH, - git_commit: process.env.GIT_COMMIT, - image_tag: process.env.IMAGE_TAG, - build_date: process.env.BUILD_DATE + git_branch: process.env.GIT_BRANCH || "", + git_commit: process.env.GIT_COMMIT || "", + image_tag: process.env.IMAGE_TAG || "", + build_date: process.env.BUILD_DATE || "" }; // Get Vision Build Info let visionBuildInfoJSON = {}; diff --git a/lib/controllers/v2/build_info_controller.js b/lib/controllers/v2/build_info_controller.js index 283fdc6f..63b213b8 100644 --- a/lib/controllers/v2/build_info_controller.js +++ b/lib/controllers/v2/build_info_controller.js @@ -6,10 +6,10 @@ const index = async req => { throw util.httpError( 401, "Unauthorized" ); } const buildInfoJSON = { - git_branch: process.env.GIT_BRANCH, - git_commit: process.env.GIT_COMMIT, - image_tag: process.env.IMAGE_TAG, - build_date: process.env.BUILD_DATE + git_branch: process.env.GIT_BRANCH || "", + git_commit: process.env.GIT_COMMIT || "", + image_tag: process.env.IMAGE_TAG || "", + build_date: process.env.BUILD_DATE || "" }; return buildInfoJSON; }; diff --git a/package-lock.json b/package-lock.json index 1ba7d812..27bd0e14 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "geoip-lite": "^1.4.3", "h3-js": "^4.1.0", "handlebars": "^4.7.7", - "inaturalistjs": "github:inaturalist/inaturalistjs#2fc60fb0870f35427c225b73745a5c492b41637a", + "inaturalistjs": "github:inaturalist/inaturalistjs", "intl": "^1.2.5", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1", @@ -16926,7 +16926,7 @@ "inaturalistjs": { "version": "git+ssh://git@github.com/inaturalist/inaturalistjs.git#2fc60fb0870f35427c225b73745a5c492b41637a", "integrity": "sha512-0Degd6YhzSMCcj8DtFMNi3rIoukwGbRwhbqlBXmih9TsL5RZ4oxLOqHRaetcvtcDrvhG+iof0fcFC2sxkh6LmQ==", - "from": "inaturalistjs@github:inaturalist/inaturalistjs#2fc60fb0870f35427c225b73745a5c492b41637a", + "from": "inaturalistjs@github:inaturalist/inaturalistjs", "requires": { "cross-fetch": "^3.1.5", "form-data": "^4.0.0", diff --git a/package.json b/package.json index 0e2d5e5a..3c7d7cea 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "geoip-lite": "^1.4.3", "h3-js": "^4.1.0", "handlebars": "^4.7.7", - "inaturalistjs": "github:inaturalist/inaturalistjs#2fc60fb0870f35427c225b73745a5c492b41637a", + "inaturalistjs": "github:inaturalist/inaturalistjs", "intl": "^1.2.5", "joi": "^17.5.0", "joi-to-swagger": "^6.1.1",