Skip to content

Commit

Permalink
Merge pull request #26 from NYPL-discovery/tgr-main
Browse files Browse the repository at this point in the history
Tgr main
  • Loading branch information
danamansana authored Sep 30, 2024
2 parents f73595a + ae09839 commit 9839cdd
Show file tree
Hide file tree
Showing 24 changed files with 10,543 additions and 5,392 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Test and deploy
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: npm install
run: npm ci
- name: Unit Tests
run: npm test
deploy-qa:
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/qa'
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole
aws-region: us-east-1
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v2
- name: npm install
run: npm ci
- name: Deploy app to QA
run: |
terraform -chdir=provisioning/qa init -input=false
terraform -chdir=provisioning/qa apply -auto-approve -input=false
deploy-production:
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/production'
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole
aws-region: us-east-1
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v2
- name: npm install
run: npm ci
- name: Deploy app to Production
run: |
terraform -chdir=provisioning/production init -input=false
terraform -chdir=provisioning/production apply -auto-approve -input=false
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@ build/*
node_modules
.DS_Store
.lambda
provisioning/base/.terraform/*
provisioning/base/.terraform.lock.hcl
provisioning/base/dist.zip
provisioning/qa/.terraform/*
provisioning/qa/.terraform.lock.hcl
provisioning/qa/dist.zip
provisioning/production/.terraform/*
provisioning/production/.terraform.lock.hcl
provisioning/production/dist.zip
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,38 @@ To run against environment dependencies:

Because of the dependencies in this app, we need to run our deployments from EC2. Always run deployments from an EC2 instance on the sandbox account.

To find the ec2 address, log in to the AWS console, and go to EC2 instances. Look for a recent instance that has a public IP you can access with the dgdvteam.pem (ask a coworker). You will likely want to use the instance's private IP to connect.
To find the ec2 address, log in to the AWS console, and go to EC2 instances. Look for a recent instance that has a public IP you can access with the dgdvteam.pem (ask a coworker). You will likely want to use the instance's private IP to connect.

`ssh -i path/to/dgdvteam.pem [email protected]`
`ssh -i path/to/dgdvteam.pem [email protected]`

Then change to the directory that you will be running the deployment scripts from.
Then change to the directory that you will be running the deployment scripts from.

`cd /home/ec2-user/temp`

If this directory doesn't exist, you're in for more fun. Create the temp directory, then cd into it and clone this repo.
If this directory doesn't exist, you're in for more fun. Create the temp directory, then cd into it and clone this repo.

It is possible you may also need to install git. If you do, this should work:
It is possible you may also need to install git. If you do, this should work:

`sudo yum install git`

After cloning the repo, you should finally be able to
After cloning the repo, you should finally be able to

`cd scsb-ongoing-accessions`

Once cloned, you will need to setup the following:
Once cloned, you will need to setup the following:

* AWS credentials at ~/.aws/credentials (needs two profiles for qa and production deployment, named 'nypl-sandbox' and 'nypl-digital-dev' respectively -- best to get this from a coworker, too. (if you need to upload them from local to aws, use `scp -i path/to-dgdvteam.pem credentials [email protected]:~/.` then `mv credentials .aws/credentials`)
* nvm via `curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash` ... then reconnect.
* nvm via `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash` ... then reconnect.
* node 6.10.3 via `nvm install 6.10.3` , then `nvm use 6.10.3`
* copy your appropriate config/environment.env file to the server a la your credentails file. .env files are currently not in source control so need to be manually put in place, as well.

It's also possible you may need to install make. Or gcc. Or a bunch of other things. If you do, maybe these will work.
It's also possible you may need to install make. Or gcc. Or a bunch of other things. If you do, maybe these will work.

`yum install make glibc-devel gcc patch`
`yum install gcc-c++`

Once that's all in place, `npm install`. If it works, you should be good to go with deployment.

### Important Notes About convert-2-scsb-module

When there are updates to the convert-2-scsb-module, the module will need to be updated by hand. You may need to specify the exact commit / tag from github in order to update it.

### Running Deploy Scripts

Two deploy scripts are registered in `package.json`:
Expand All @@ -89,8 +85,6 @@ The test suite uses [lambda-tester](https://www.npmjs.com/package/lambda-tester)

`npm test`

Note that `event.json` contains a sample API Gateway event that can, in theory, be used with `node-lambda` to emulate a lambda invocation locally, but that won't work until `node-lambda` supports `--profile` due to a quirk in aws global credential management. In practice, running the app as a persistent express server via `npm run run-[environment]` feels more natural for local ad hoc testing anyway.

### Test Fixtures

A series of local test fixtures representing responses from the nypl data api, maintained in `./test/data/*.json`. These allow the test suite to run against a fixed set of data. If any fixtures need to be updated or added, a script is provided:
Expand Down
1 change: 0 additions & 1 deletion app-local.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const app = require('./app')
const port = 3000

Expand Down
8 changes: 4 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ app.get('/api/v0.1/recap/nypl-bibs', (req, res, next) => {
customerCode = req.query.customerCode
}

let barcode = req.query.barcode
let bibId = req.query.bibId
let includeFullBibTree = (req.query.includeFullBibTree === 'true')
const barcode = req.query.barcode
const bibId = req.query.bibId
const includeFullBibTree = (req.query.includeFullBibTree === 'true')

if (!customerCode || !(barcode || bibId)) {
return handleError(new errors.InvalidParameterError('Missing barcode and customerCode paramaters or bibId and customerCode parameter'), req, res)
Expand Down Expand Up @@ -84,7 +84,7 @@ app.get('/api/v0.1/recap/nypl-bibs', (req, res, next) => {
// END: TEMPORARY overide to test mixed-bib split
// Format as scsb xml:
.then((bibsAndItems) => {
let [bibs, items] = bibsAndItems
const [bibs, items] = bibsAndItems
return scsbXmlFormatter.bibsAndItemsToScsbXml(bibs, items, customerCode)
})
// Write response:
Expand Down
75 changes: 38 additions & 37 deletions convert-test-marc-to-sierra.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const convert2Scsb = require('convert-2-scsb-module')
const convert2Scsb = require('./lib/convert-2-scsb-module')
const H = require('highland')
const marc = require('marcjs')
const fs = require('fs')
const xml2js = require('xml2js')
const builder = new xml2js.Builder({renderOpts: {pretty: false}, headless: true})
const builder = new xml2js.Builder({ renderOpts: { pretty: false }, headless: true })

var barcodes = [{barcode: 'NYPLTST67891', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67892', customercode: 'NA', m876o: '2', m876s: '212', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67893', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67894', customercode: 'NA', m876o: '2', m876s: '211', m876y: '57', boundwith: false}, {barcode: 'NYPLTST67895', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67896', customercode: 'NA', m876o: '2', m876s: '227', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67881', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67882', customercode: 'NB', m876o: '2', m876s: '211', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67883', customercode: 'NH', m876o: '2', m876s: '211', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67884', customercode: 'NP', m876o: '2', m876s: '211', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67885', customercode: 'NW', m876o: 'u', m876s: '210', m876y: '', boundwith: false}, {barcode: 'NYPLTST67886', customercode: 'NX', m876o: '2', m876s: '211', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67887', customercode: 'GN', m876o: '2', m876s: '211', m876y: '55', boundwith: false}, {barcode: 'NYPLTST67888', customercode: 'NN', m876o: '2', m876s: '211', m876y: '65', boundwith: false}, {barcode: 'NYPLTST67889', customercode: 'NO', m876o: '2', m876s: '211', m876y: '61', boundwith: false}, {barcode: 'NYPLTST67880', customercode: 'NQ', m876o: 'p', m876s: '211', m876y: '37', boundwith: false}, {barcode: 'NYPLTST67870', customercode: 'NR', m876o: '4', m876s: '211', m876y: '66', boundwith: false}]
var barcodesBoundWith = [{barcode: 'NYPLTST67897', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: true}, {barcode: 'NYPLTST67897', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: true}, {barcode: 'NYPLTST67897', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: true}]
var counter = 90000000
var exmapleData = {}
const barcodes = [{ barcode: 'NYPLTST67891', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67892', customercode: 'NA', m876o: '2', m876s: '212', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67893', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67894', customercode: 'NA', m876o: '2', m876s: '211', m876y: '57', boundwith: false }, { barcode: 'NYPLTST67895', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67896', customercode: 'NA', m876o: '2', m876s: '227', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67881', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67882', customercode: 'NB', m876o: '2', m876s: '211', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67883', customercode: 'NH', m876o: '2', m876s: '211', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67884', customercode: 'NP', m876o: '2', m876s: '211', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67885', customercode: 'NW', m876o: 'u', m876s: '210', m876y: '', boundwith: false }, { barcode: 'NYPLTST67886', customercode: 'NX', m876o: '2', m876s: '211', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67887', customercode: 'GN', m876o: '2', m876s: '211', m876y: '55', boundwith: false }, { barcode: 'NYPLTST67888', customercode: 'NN', m876o: '2', m876s: '211', m876y: '65', boundwith: false }, { barcode: 'NYPLTST67889', customercode: 'NO', m876o: '2', m876s: '211', m876y: '61', boundwith: false }, { barcode: 'NYPLTST67880', customercode: 'NQ', m876o: 'p', m876s: '211', m876y: '37', boundwith: false }, { barcode: 'NYPLTST67870', customercode: 'NR', m876o: '4', m876s: '211', m876y: '66', boundwith: false }]
const barcodesBoundWith = [{ barcode: 'NYPLTST67897', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: true }, { barcode: 'NYPLTST67897', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: true }, { barcode: 'NYPLTST67897', customercode: 'NA', m876o: '2', m876s: '211', m876y: '55', boundwith: true }]
let counter = 90000000
const exmapleData = {}

convert2Scsb.parseMrc.nonNumericBarcodesOkay = true

Expand All @@ -25,7 +25,7 @@ H(new marc.Iso2709Reader(fs.createReadStream('data/NYPLTEST.mrc')))
record = convert2Scsb.parseMrc.convertToJsonCheckSize(record)
record.bNumber = convert2Scsb.parseMrc.extractBnumber(record.mij) // 907|a
record.bNumber = `.b${++counter}`
var barcode = null
let barcode = null

if (counter < 90000013) {
barcode = barcodes.shift()
Expand All @@ -34,70 +34,70 @@ H(new marc.Iso2709Reader(fs.createReadStream('data/NYPLTEST.mrc')))
barcode = barcodesBoundWith[Math.floor(Math.random() * (3 - 0) + 0)]
}

var inumber = `.i${Math.floor(Math.random() * (99999999 - 10000000) + 10000000)}`
var callnumber = `JFA-${Math.floor(Math.random() * (9999 - 100) + 100)}`
const inumber = `.i${Math.floor(Math.random() * (99999999 - 10000000) + 10000000)}`
const callnumber = `JFA-${Math.floor(Math.random() * (9999 - 100) + 100)}`

record.mij.fields.push({
'852': {
'ind1': ' ',
'ind2': ' ',
'subfields': [
852: {
ind1: ' ',
ind2: ' ',
subfields: [
{
'a': inumber
a: inumber
},
{
'b': 'rcxx2'
b: 'rcxx2'
},
{
'h': '*ZZ-27060'
h: '*ZZ-27060'
}
]
}
})

record.mij.fields.push({
'876': {
'ind1': ' ',
'ind2': ' ',
'subfields': [
876: {
ind1: ' ',
ind2: ' ',
subfields: [
{
'a': inumber
a: inumber
},
{
'j': '-'
j: '-'
},
{
'h': callnumber
h: callnumber
},
{
'k': 'rcxx2'
k: 'rcxx2'
},
{
'o': barcode.m876o
o: barcode.m876o
},
{
'p': barcode.barcode
p: barcode.barcode
},
{
's': barcode.m876s
s: barcode.m876s
},
{
't': '1'
t: '1'
},
{
'y': barcode.m876y
y: barcode.m876y
}
]
}
})

record.mij.fields.push({
'952': {
'ind1': ' ',
'ind2': ' ',
'subfields': [
952: {
ind1: ' ',
ind2: ' ',
subfields: [
{
'h': callnumber
h: callnumber
}
]
}
Expand Down Expand Up @@ -146,16 +146,17 @@ H(new marc.Iso2709Reader(fs.createReadStream('data/NYPLTEST.mrc')))
// pull out the data we need for the sheet
record.dataFields.forEach((df) => {
if (df['245']) {
var title = ''
let title = ''

df['245'].subfields.forEach((sf) => {
if (sf['a']) title = title + sf['a']
if (sf['b']) title = title + sf['b']
if (sf.a) title = title + sf.a
if (sf.b) title = title + sf.b
})
console.log(barcode.barcode + ',' + title + ',"' + record.mij.leader.substr(7, 1) + '"')
}
})
exmapleData[barcode.barcode].push(record.xml)
return null
})
.done(() => {
fs.writeFile('data/mock.json', JSON.stringify(exmapleData, null, 2), function (err) {
Expand Down
Loading

0 comments on commit 9839cdd

Please sign in to comment.