Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sha and version to ‘/‘ endpoint #574

Merged
merged 8 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
build-and-deploy:
name: Build and Deploy
needs: upload-package-lock-json
uses: clearlydefined/operations/.github/workflows/app-build-and-deploy.yml@v2.0.0
uses: clearlydefined/operations/.github/workflows/app-build-and-deploy.yml@v3.0.0
secrets:
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
AZURE_WEBAPP_PUBLISH_PROFILE: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_DEV }}
Expand Down
7 changes: 6 additions & 1 deletion DevDockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
FROM node:18-bullseye
ENV APPDIR=/opt/service

# Set environment variables from build arguments
ARG BUILD_NUMBER=0
ENV CRAWLER_BUILD_NUMBER=$BUILD_NUMBER
ENV BUILD_NUMBER=$APP_VERSION
ARG APP_VERSION="UNKNOWN"
ENV APP_VERSION=$APP_VERSION
ARG BUILD_SHA="UNKNOWN"
ENV BUILD_SHA=$BUILD_SHA

# Ruby and Python Dependencies
RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests curl bzip2 build-essential libssl-dev libreadline-dev zlib1g-dev cmake python3 python3-dev python3-pip xz-utils libxml2-dev libxslt1-dev libpopt0 && \
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
FROM node:18-bullseye
ENV APPDIR=/opt/service

ARG BUILD_NUMBER=0
ENV CRAWLER_BUILD_NUMBER=$BUILD_NUMBER
# Set environment variables from build arguments
ARG APP_VERSION="UNKNOWN"
ENV APP_VERSION=$APP_VERSION
ARG BUILD_SHA="UNKNOWN"
ENV BUILD_SHA=$BUILD_SHA

# Ruby and Python Dependencies
RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests curl bzip2 build-essential libssl-dev libreadline-dev zlib1g-dev cmake python3 python3-dev python3-pip xz-utils libxml2-dev libxslt1-dev libpopt0 && \
Expand Down
4 changes: 3 additions & 1 deletion config/cdConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ module.exports = {
attenuation: {
ttl: 3000
}
}
},
appVersion: config.get('APP_VERSION'),
buildsha: config.get('BUILD_SHA')
}
}
4 changes: 1 addition & 3 deletions ghcrawler/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ function configureApp(service, logger) {
app.use('/requests', require('./routes/requests')(service))

// to keep AlwaysOn flooding logs with errors
app.get('/', (request, response) => {
response.helpers.send.noContent()
})
app.use('/', require('./routes/index')(config.get('BUILD_SHA'), config.get('APP_VERSION')))

// Catch 404 and forward to error handler
const requestHandler = (request, response, next) => {
Expand Down
20 changes: 20 additions & 0 deletions ghcrawler/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation and others. Licensed under the MIT license.
// SPDX-License-Identifier: MIT
const express = require('express')
const router = express.Router()

router.get('/', function (req, res) {
const msg = `{ "status": "OK", "version": "${version}", "sha": "${sha}" }`
res.status(200).send(msg)
})

module.exports = router

let version
let sha
function setup(buildsha, appVersion) {
version = appVersion
sha = buildsha
return router
}
Comment on lines +13 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but I'm not sure how well I like keeping the values as global state in this file. Couldn't we just access the config directly here instead of passing as variables?
Additionally, I'm wondering if it'd be worth to still escape these values, even though they should usually be under our control.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style matches that used in other endpoints. I'm open to other options.

module.exports = setup
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const uuid = require('node-uuid')
const logger = require('./providers/logging/logger')({
crawlerId: config.get('CRAWLER_ID') || uuid.v4(),
crawlerHost: config.get('CRAWLER_HOST'),
buildNumber: config.get('CRAWLER_BUILD_NUMBER') || 'local'
appVersion: config.get('APP_VERSION') || 'local'
})

run(defaults, logger, searchPath, maps)