Merge pull request #459 from LLK/hotfix/s3cmd

[Develop] Use s3cmd for S3 deployment
This commit is contained in:
Ray Schamp 2016-04-29 16:26:53 -04:00
commit 32677659c3
8 changed files with 32 additions and 61 deletions

1
.gitignore vendored
View file

@ -17,3 +17,4 @@ npm-*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
deploy.zip
ENV

View file

@ -1,7 +1,7 @@
language: node_js
node_js:
- '4.2'
sudo: false
sudo: required
cache:
directories:
- node_modules
@ -37,6 +37,9 @@ addons:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
install:
- sudo -H pip install -r requirements.txt
- npm install
deploy:
- provider: script
skip_cleanup: $SKIP_CLEANUP

View file

@ -1,6 +1,7 @@
ESLINT=./node_modules/.bin/eslint
NODE=node
SASSLINT=./node_modules/.bin/sass-lint -v
S3CMD=s3cmd
TAP=./node_modules/.bin/tap
WATCH=./node_modules/.bin/watch
WEBPACK=./node_modules/.bin/webpack
@ -33,7 +34,7 @@ webpack:
$(WEBPACK) --bail
sync-s3:
$(NODE) ./bin/deploy-to-s3.js
$(S3CMD) sync -P --delete-removed --exclude '.DS_Store' ./build/ s3://$(S3_BUCKET_NAME)/
sync-fastly:
$(NODE) ./bin/configure-fastly.js

View file

@ -75,6 +75,25 @@ Use `^C` to stop the node process `npm start` starts.
npm test
```
### To Deploy
```bash
npm install
virtualenv ENV
. ENV/bin/activate
pip install -r requirements.txt
make deploy
```
| Variable | Default | Description |
| ------------------------ | ------- | ------------------------------------------------ |
| `FASTLY_SERVICE_ID` | `''` | Fastly service ID for `bin/configure-fastly.js` |
| `FASTLY_API_KEY` | `''` | Fastly API key for `bin/configure-fastly.js` |
| `FASTLY_ACTIVATE_CHANGES`| `false` | Activate changes and purge all after configuring |
| `AWS_ACCESS_KEY_ID` | `''` | AWS access key id for S3 |
| `AWS_SECRET_ACCESS_KEY` | `''` | AWS secret access key for S3 |
| `S3_BUCKET_NAME` | `''` | S3 bucket name to deploy into |
### Current issues with the development
We're currently in the process of transitioning into this web client from Scratch's existing structure. As we transition, there are going to be some issues along the way that relate to how this client needs to interact with the existing infrastructure to work properly in production.

View file

@ -255,6 +255,10 @@ async.auto({
fastly.activateVersion(results.version, function (err, response) {
if (err) throw new Error(err);
process.stdout.write('Successfully configured and activated version ' + response.number + '\n');
fastly.purgeAll(FASTLY_SERVICE_ID, function (err) {
if (err) throw new Error(err);
process.stdout.write('Purged all.\n');
});
});
}
}

View file

@ -1,57 +0,0 @@
var path = require('path');
var s3 = require('s3');
var util = require('util');
const IGNORE_FILES = [
'.DS_Store'
];
var s3Client = s3.createClient({
s3Options: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID || '',
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || ''
}
});
var localDir = process.env.BUILD_DIRECTORY;
if (!localDir) {
localDir = path.resolve(__dirname, '../build');
} else {
if (!path.isAbsolute(localDir)) {
localDir = path.join(process.cwd(), localDir);
}
}
var skipped = 0;
var uploaded = 0;
var sync = s3Client.uploadDir({
deleteRemoved: true,
localDir: localDir,
getS3Params: function (localfile, stat, callback) {
if (IGNORE_FILES.indexOf(path.basename(localfile)) != -1) {
skipped++;
return callback(null, null);
}
callback(null, {});
},
s3Params: {
Prefix: '',
Bucket: process.env.S3_BUCKET_NAME || '',
ACL: 'public-read'
}
});
sync.on('error', function (err) {
throw new Error('Failed to sync with S3: ' + err);
});
sync.on('fileUploadEnd', function () {uploaded++;});
sync.on('end', function () {
process.stdout.write(util.format(
'Uploaded %d local files. Removed %d remote files.\n',
uploaded, sync.deleteTotal
));
process.exit();
});

View file

@ -64,7 +64,6 @@
"react-redux": "4.4.0",
"react-slick": "0.9.2",
"redux-thunk": "2.0.1",
"s3": "4.4.0",
"sass-lint": "1.5.1",
"sass-loader": "2.0.1",
"scratchr2_translations": "git://github.com/LLK/scratchr2_translations.git#master",

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
s3cmd==1.6.1