From ec3fcb6c831eeedb266e630c2a2927930be43981 Mon Sep 17 00:00:00 2001 From: Siddharth Rawat Date: Fri, 12 Jan 2024 14:48:08 -0500 Subject: [PATCH] fix: update build script and healthz endpoint --- .github/workflows/packer-build.yml | 19 ++++++++++++++++++- aws/scripts/install.sh | 3 ++- src/routes/health.route.js | 2 +- tests/index.test.js | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/workflows/packer-build.yml b/.github/workflows/packer-build.yml index 3c56cdb..fadef6b 100644 --- a/.github/workflows/packer-build.yml +++ b/.github/workflows/packer-build.yml @@ -1,4 +1,4 @@ -name: Instance Refresh +name: Build on: workflow_dispatch: @@ -8,6 +8,23 @@ jobs: tests: runs-on: ubuntu-latest environment: ${{ vars.ENVIRONMENT }} + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres:latest + ports: + - 5432:5432 + env: + POSTGRES_DB: ${{ vars.DATABASE }} + POSTGRES_USER: ${{ vars.DBUSER }} + POSTGRES_PASSWORD: ${{ secrets.DBPASSWORD }} + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 name: Run unit tests steps: - uses: actions/checkout@v4 diff --git a/aws/scripts/install.sh b/aws/scripts/install.sh index abcb699..fbdb84c 100644 --- a/aws/scripts/install.sh +++ b/aws/scripts/install.sh @@ -16,6 +16,7 @@ echo "| echo "| INSTALL SCRIPT v1.0 |" echo "| |" echo "+-----------------------------------------------------------------------------------------------------------------------------------------+" +sudo apt-get update --quiet && sudo apt-get upgrade -y # Install zip and unnzip echo "+-----------------------------------------------------------------------------------------------------------------------------------------+" @@ -105,7 +106,7 @@ echo "| echo "| Installing AWS Cloudwatch Agent |" echo "| |" echo "+-----------------------------------------------------------------------------------------------------------------------------------------+" -wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb +wget -q https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb AWSCLDWTCH=$? if [ $AWSCLDWTCH -eq 0 ]; then sleep 5 diff --git a/src/routes/health.route.js b/src/routes/health.route.js index eb92cb1..2b4c5fc 100644 --- a/src/routes/health.route.js +++ b/src/routes/health.route.js @@ -4,6 +4,6 @@ import { health } from '../controllers/health.controller.js' const router = express.Router() router.get('/', health) -router.get('/health', health) +router.get('/healthz', health) export { router as healthRoute } diff --git a/tests/index.test.js b/tests/index.test.js index 246aae2..0da263f 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -4,7 +4,7 @@ import app from '../app.js' describe('Unit Test Suite', () => { it('GET /health API endpoint', (done) => { supertest(app) - .get('/health') + .get('/healthz') .expect(200) .end((err, res) => { if (err) return done(err)