Use s3cmd to sync with S3

This commit is contained in:
Ray Schamp 2016-04-29 14:33:04 -04:00
parent c41c40340a
commit dd1c2c1627
7 changed files with 27 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

@ -52,7 +52,7 @@ Use `^C` to stop the node process `npm start` starts.
| `API_HOST` | `https://api.scratch.mit.edu` | Hostname for API requests |
| `NODE_ENV` | `null` | If not `production`, app acts like development |
| `PORT` | `8333` | Port for devserver (http://localhost:XXXX) |
| `FALLBACK` | `''` | Pass-through location for old site |
| `FALLBACK` | `''` | Pass-through location for old site |
**NOTE:** Because by default `API_HOST=https://api.scratch.mit.edu`, please be aware that, by default, you will be seeing and interacting with real data on the Scratch website.
@ -61,6 +61,24 @@ 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` |
| `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

@ -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