Skip to content

Commit

Permalink
Merge branch 'main' into node20
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Jul 10, 2024
2 parents b345d76 + 25b173b commit e171300
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 5 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/CICD-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ 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")" >> $GITHUB_ENV

- name: Build/Push Dev inaturalistapi
uses: docker/build-push-action@v5
with:
context: .
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=${{ env.BUILD_DATE }}
- name: Build/Push Dev inaturalistapi-cleanup
uses: docker/build-push-action@v5
Expand All @@ -45,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
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/CICD-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ 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")" >> $GITHUB_ENV

- name: Build/Push Main inaturalistapi
uses: docker/build-push-action@v5
with:
Expand All @@ -38,6 +41,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=${{ env.BUILD_DATE }}
- name: Build/Push Main inaturalistapi-cleanup
uses: docker/build-push-action@v5
Expand All @@ -48,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
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions lib/controllers/v2/app_build_info_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// eslint-disable-next-line camelcase
const { build_info } = require( "inaturalistjs" );
const process = require( "process" );
const fetch = require( "node-fetch" );

Check failure on line 4 in lib/controllers/v2/app_build_info_controller.js

View workflow job for this annotation

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

'node-fetch' should be listed in the project's dependencies. Run 'npm i -S node-fetch' to add it
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
// eslint-disable-next-line camelcase
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
};
19 changes: 19 additions & 0 deletions lib/controllers/v2/build_info_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const process = require( "process" );
const util = require( "../../util" );

const index = async req => {
if ( !req.userSession || ( req.userSession && !req.userSession.isAdmin ) ) {
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
};
36 changes: 36 additions & 0 deletions openapi/paths/v2/app_build_info.js
Original file line number Diff line number Diff line change
@@ -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
};
};
36 changes: 36 additions & 0 deletions openapi/paths/v2/build_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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",
security: [{
userJwtRequired: []
}],
responses: {
200: {
description: "Build information",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/BuildInfo"
}
}
}
},
default: {
$ref: "#/components/responses/Error"
}
},
"x-unpublished": true
};

return {
GET
};
};
3 changes: 3 additions & 0 deletions openapi/schema/request/app_build_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const Joi = require( "joi" );

module.exports = Joi.object( ).keys( {} );
3 changes: 3 additions & 0 deletions openapi/schema/request/build_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const Joi = require( "joi" );

module.exports = Joi.object( ).keys( {} );
22 changes: 22 additions & 0 deletions openapi/schema/response/app_build_info.js
Original file line number Diff line number Diff line change
@@ -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 );
8 changes: 8 additions & 0 deletions openapi/schema/response/build_info.js
Original file line number Diff line number Diff line change
@@ -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 );

0 comments on commit e171300

Please sign in to comment.