Skip to content

Commit

Permalink
Rename some CI variables for clarity, enhance docs
Browse files Browse the repository at this point in the history
  • Loading branch information
levinmr committed Feb 28, 2024
1 parent a1380ed commit 6997746
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 75 deletions.
50 changes: 25 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Code Checkout
- name: Code checkout
uses: actions/checkout@v4
- name: Install Node
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: 'npm'
- name: install dependencies
- name: Install node dependencies
run: npm ci
- name: lint javascript
- name: Lint javascript
run: npm run lint
test:
needs: lint
runs-on: ubuntu-latest
#Spin up postgres as a service, wait till healthy before moving on. Uses latest Postgres Version.
# Start Postgres as a service, wait until healthy. Uses latest Postgres version.
services:
postgres:
image: postgres:latest
Expand All @@ -36,16 +36,16 @@ jobs:
--health-timeout 5s
--health-retries 5
steps:
- name: Code Checkout
- name: Code checkout
uses: actions/checkout@v4
- name: Install Node
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: 'npm'
- name: install dependencies
- name: Install node dependencies
run: npm ci
- name: run tests
- name: Run tests
run: npm test
deploy_dev:
needs:
Expand All @@ -55,15 +55,15 @@ jobs:
uses: 18F/analytics-reporter-api/.github/workflows/deploy.yml@develop
with:
APP_NAME: ${{ vars.APP_NAME_DEV }}
DB_NAME: ${{ vars.DB_NAME_DEV }}
NEW_RELIC_APP_NAME:
ORGANIZATION_NAME: gsa-opp-analytics
SPACE_NAME: analytics-dev
CF_ORGANIZATION_NAME: ${{ vars.CF_ORGANIZATION_NAME }}
CF_SPACE_NAME: ${{ vars.CF_SPACE_NAME_DEV }}
DB_SERVICE_NAME: ${{ vars.DB_SERVICE_NAME_DEV }}
NEW_RELIC_APP_NAME: ${{ vars.NEW_RELIC_APP_NAME_DEV }}
secrets:
API_DATA_GOV_SECRET: ${{ secrets.API_DATA_GOV_SECRET_DEV }}
CF_USERNAME: ${{ secrets.CF_USERNAME_DEV }}
CF_PASSWORD: ${{ secrets.CF_PASSWORD_DEV }}
API_DATA_GOV_SECRET: ${{ secrets.API_DATA_GOV_SECRET_DEV }}
NEW_RELIC_LICENSE_KEY:
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY_DEV }}
deploy_stg:
needs:
- lint
Expand All @@ -72,15 +72,15 @@ jobs:
uses: 18F/analytics-reporter-api/.github/workflows/deploy.yml@develop
with:
APP_NAME: ${{ vars.APP_NAME_STG }}
DB_NAME: ${{ vars.DB_NAME_STG }}
NEW_RELIC_APP_NAME:
ORGANIZATION_NAME: gsa-opp-analytics
SPACE_NAME: analytics-staging
CF_ORGANIZATION_NAME: ${{ vars.CF_ORGANIZATION_NAME }}
CF_SPACE_NAME: ${{ vars.CF_SPACE_NAME_STG }}
DB_SERVICE_NAME: ${{ vars.DB_SERVICE_NAME_STG }}
NEW_RELIC_APP_NAME: ${{ vars.NEW_RELIC_APP_NAME_STG }}
secrets:
API_DATA_GOV_SECRET: ${{ secrets.API_DATA_GOV_SECRET_STG }}
CF_USERNAME: ${{ secrets.CF_USERNAME_STG }}
CF_PASSWORD: ${{ secrets.CF_PASSWORD_STG }}
API_DATA_GOV_SECRET: ${{ secrets.API_DATA_GOV_SECRET_STG }}
NEW_RELIC_LICENSE_KEY:
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY_STG }}
deploy_prd:
needs:
- lint
Expand All @@ -89,12 +89,12 @@ jobs:
uses: 18F/analytics-reporter-api/.github/workflows/deploy.yml@develop
with:
APP_NAME: ${{ vars.APP_NAME_PRD }}
DB_NAME: ${{ vars.DB_NAME_PRD }}
CF_ORGANIZATION_NAME: ${{ vars.CF_ORGANIZATION_NAME }}
CF_SPACE_NAME: ${{ vars.CF_SPACE_NAME_PRD }}
DB_SERVICE_NAME: ${{ vars.DB_SERVICE_NAME_PRD }}
NEW_RELIC_APP_NAME: ${{ vars.NEW_RELIC_APP_NAME_PRD }}
ORGANIZATION_NAME: gsa-opp-analytics
SPACE_NAME: analytics-production
secrets:
API_DATA_GOV_SECRET: ${{ secrets.API_DATA_GOV_SECRET_PRD }}
CF_USERNAME: ${{ secrets.CF_USERNAME_PRD }}
CF_PASSWORD: ${{ secrets.CF_PASSWORD_PRD }}
API_DATA_GOV_SECRET: ${{ secrets.API_DATA_GOV_SECRET_PRD }}
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY_PRD }}
46 changes: 22 additions & 24 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,71 @@ on:
APP_NAME:
required: true
type: string
DB_NAME:
CF_ORGANIZATION_NAME:
required: true
type: string
NEW_RELIC_APP_NAME:
type: string
ORGANIZATION_NAME:
CF_SPACE_NAME:
required: true
type: string
SPACE_NAME:
DB_SERVICE_NAME:
required: true
type: string
NEW_RELIC_APP_NAME:
type: string
secrets:
API_DATA_GOV_SECRET:
required: true
CF_USERNAME:
required: true
CF_PASSWORD:
required: true
API_DATA_GOV_SECRET:
required: true
NEW_RELIC_LICENSE_KEY:

env:
API_DATA_GOV_SECRET: ${{ secrets.API_DATA_GOV_SECRET }}
APP_NAME: ${{ inputs.APP_NAME }}
DB_NAME: ${{ inputs.DB_NAME }}
NEW_RELIC_APP_NAME: ${{ inputs.NEW_RELIC_APP_NAME }}
ORGANIZATION_NAME: ${{ inputs.ORGANIZATION_NAME }}
SPACE_NAME: ${{ inputs.SPACE_NAME }}
DB_SERVICE_NAME: ${{ inputs.DB_SERVICE_NAME }}
CF_USERNAME: ${{ secrets.CF_USERNAME }}
CF_PASSWORD: ${{ secrets.CF_PASSWORD }}
API_DATA_GOV_SECRET: ${{ secrets.API_DATA_GOV_SECRET }}
CF_ORGANIZATION_NAME: ${{ inputs.CF_ORGANIZATION_NAME }}
CF_SPACE_NAME: ${{ inputs.CF_SPACE_NAME }}
NEW_RELIC_APP_NAME: ${{ inputs.NEW_RELIC_APP_NAME }}
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}

jobs:
deploy_api:
runs-on: ubuntu-latest
steps:
- name: Code Checkout
- name: Code checkout
uses: actions/checkout@v4
- name: Install Node
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: 'npm'
- name: install dependencies
- name: Install node dependencies
run: npm ci
- name: Replace env vars in manifest.yml file
- name: Install cloud foundry CLI for interacting with cloud.gov
run: |
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
- name: Run envsubst on manifest.yml to set environment specific values
run: |
sudo apt-get update
sudo apt-get install gettext
mv manifest.yml manifest.yml.src
envsubst < manifest.yml.src > manifest.yml
cat manifest.yml
- name: Replace config.js and knexfile.js with .cloudgov versions of those files
run: |
rm ./src/config.js
mv ./src/config.js.cloudgov ./src/config.js
rm knexfile.js
mv knexfile.js.cloudgov knexfile.js
- name: Install CF CLI
run: |
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
- name: Login to cloud.gov and deploy
run: |
set -e
# Log into cloud.gov
cf api api.fr.cloud.gov
cf login -u $CF_USERNAME -p $CF_PASSWORD -o $ORGANIZATION_NAME -s $SPACE_NAME
cat manifest.yml
cf login -u $CF_USERNAME -p $CF_PASSWORD -o $CF_ORGANIZATION_NAME -s $CF_SPACE_NAME
cf push -f "./manifest.yml" --no-start
cf set-env $APP_NAME API_DATA_GOV_SECRET "$API_DATA_GOV_SECRET"
cf restage $APP_NAME
Expand Down
24 changes: 4 additions & 20 deletions knexfile.js.cloudgov
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
const VCAP_SERVICES_JSON = JSON.parse(process.env.VCAP_SERVICES);

module.exports = {
development: {
client: 'postgresql',
connection: {
database: 'analytics-reporter'
}
},
production: {
client: 'postgresql',
connection: {
host : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["host"],
user : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["username"],
password : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["password"],
database : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["db_name"],
host : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["host"],
user : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["username"],
password : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["password"],
database : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["db_name"],
port: 5432,
ssl : true
},
Expand All @@ -25,15 +19,5 @@ module.exports = {
migrations: {
tableName: 'knex_migrations'
}
},
test: {
client: 'postgresql',
connection: {
user: process.env.CIRCLECI ? 'postgres' : undefined,
database: 'analytics-api-test'
},
migrations: {
tableName: 'knex_migrations'
}
}
};
4 changes: 2 additions & 2 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ applications:
instances: 1
memory: 128M
buildpacks:
- nodejs_buildpack
- nodejs_buildpack
command: "chmod +x ./entrypoint.sh && ./entrypoint.sh"
services:
- ${DB_NAME}
- ${DB_SERVICE_NAME}
stack: cflinuxfs4
env:
API_DATA_GOV_SECRET: ${API_DATA_GOV_SECRET}
Expand Down
8 changes: 4 additions & 4 deletions src/config.js.cloudgov
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module.exports = {
api_data_gov_secret: process.env.API_DATA_GOV_SECRET,
port: process.env.PORT || 4444,
postgres: {
host : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["host"],
user : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["username"],
password : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["password"],
database : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["db_name"],
host : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["host"],
user : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["username"],
password : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["password"],
database : VCAP_SERVICES_JSON["aws-rds"][0]["credentials"]["db_name"],
port: 5432,
ssl : true
},
Expand Down

0 comments on commit 6997746

Please sign in to comment.