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

fix(dev): fix Localstack yet again #252

Merged
merged 5 commits into from
Sep 2, 2020
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: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ services:
- LOGO_S3_BUCKET=local-logo-bucket
- FORMSG_SDK_MODE=development
- BOUNCE_LIFE_SPAN=1800000
- AWS_ACCESS_KEY_ID=fakeKey
mantariksh marked this conversation as resolved.
Show resolved Hide resolved
- AWS_SECRET_ACCESS_KEY=fakeSecret
- GA_TRACKING_ID
- SENTRY_CONFIG_URL
- TWILIO_ACCOUNT_SID
Expand Down
14 changes: 8 additions & 6 deletions docs/DEPLOYMENT_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ The following env variables are set in Travis:
| Variable | Description |
| :---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `AWS_REGION` | AWS region. |
| `AWS_ACCESS_KEY_ID` | AWS IAM access key ID used to access S3. |
| `AWS_SECRET_ACCESS_KEY` | AWS IAM access secret used to access S3. |
| `IMAGE_S3_BUCKET` | Name of S3 bucket for image field uploads. |
| `LOGO_S3_BUCKET` | Name of S3 bucket for form logo uploads. |
| `LOGO_S3_BUCKET` | Name of S3 bucket for form logo uploads. |
Expand Down Expand Up @@ -258,9 +260,9 @@ If this feature is enabled, storage mode forms will also support authentication

### Tests

| Variable | Description |
| :--------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `MONGO_BINARY_VERSION` | Version of the Mongo binary used. Defaults to `'latest'` according to [MongoMemoryServer](https://github.com/nodkz/mongodb-memory-server) docs. |
| `PWD` | Path of working directory. |
| `MOCK_WEBHOOK_CONFIG_FILE` | Path of configuration file for mock webhook server |
| `MOCK_WEBHOOK_PORT` | Port of mock webhook server |
| Variable | Description |
| :------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `MONGO_BINARY_VERSION` | Version of the Mongo binary used. Defaults to `'latest'` according to [MongoMemoryServer](https://github.com/nodkz/mongodb-memory-server) docs. |
| `PWD` | Path of working directory. |
| `MOCK_WEBHOOK_CONFIG_FILE` | Path of configuration file for mock webhook server |
| `MOCK_WEBHOOK_PORT` | Port of mock webhook server |
6 changes: 3 additions & 3 deletions init-localstack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ until $(curl --output /dev/null --silent --head --fail http://localhost:4572); d
printf 'Waiting for Localstack to be ready...'
sleep 5
done
awslocal s3 mb s3://$IMAGE_S3_BUCKET
awslocal s3 mb s3://$LOGO_S3_BUCKET
awslocal s3 mb s3://$ATTACHMENT_S3_BUCKET
awslocal --endpoint-url=http://localhost:4572 s3 mb s3://$IMAGE_S3_BUCKET
awslocal --endpoint-url=http://localhost:4572 s3 mb s3://$LOGO_S3_BUCKET
awslocal --endpoint-url=http://localhost:4572 s3 mb s3://$ATTACHMENT_S3_BUCKET
set +x
29 changes: 10 additions & 19 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import nodemailer from 'nodemailer'
import directTransport from 'nodemailer-direct-transport'
import Mail from 'nodemailer/lib/mailer'
import SMTPPool from 'nodemailer/lib/smtp-pool'
import { promisify } from 'util'

import defaults from './defaults'
import { createLoggerWithLabel } from './logger'
Expand Down Expand Up @@ -379,25 +380,15 @@ const cookieSettings: SessionOptions['cookie'] = {
// Functions
const configureAws = async () => {
if (!isDev) {
const getCredentials = () => {
return new Promise((resolve, reject) => {
aws.config.getCredentials((err) => {
if (err) {
reject(err)
} else {
resolve()
}
})
})
}

await getCredentials()
if (!aws.config.credentials.accessKeyId) {
throw new Error(`AWS Access Key Id is missing`)
}
if (!aws.config.credentials.secretAccessKey) {
throw new Error(`AWS Secret Access Key is missing`)
}
// Convert to async function, then call and await
await promisify(aws.config.getCredentials)()
}
// In dev environment, credentials should be set from env vars
if (!aws.config.credentials.accessKeyId) {
throw new Error(`AWS Access Key Id is missing`)
}
if (!aws.config.credentials.secretAccessKey) {
throw new Error(`AWS Secret Access Key is missing`)
}
}

Expand Down