Giter Site home page Giter Site logo

stojanovic / scottyjs Goto Github PK

View Code? Open in Web Editor NEW
707.0 12.0 37.0 6.45 MB

Deploy static websites and single page apps to AWS S3 and CloudFront with a single command

Home Page: http://medium.com/@slobodan/single-command-deployment-for-single-page-apps-29941d62ef97

License: MIT License

JavaScript 98.29% CSS 0.60% HTML 1.11%
static-site deployment aws-s3

scottyjs's Introduction

Scotty.js

As you probably noticed, Scotty.js is not active anymore. Working on Scotty.js was fun, but AWS released AWS Amplify in the meantime, and tools such as Scotty.js are no longer needed. Please take a look at the AWS Amplify Console. It's an excellent tool for hosting static websites and single-page applications.


Deploy static websites or folders to AWS S3 with a single command

scotty header

Build Status npm npm npm Join the chat at https://gitter.im/scottyjs/scotty

Install

Scotty.js is available on NPM. Install it as a global dependency to be able to use scotty command anywhere:

npm install scottyjs --global

Use

Beam me up, Scotty

To deploy a static folder to AWS S3 run:

scotty {options}

or

beam-me-up {options}

Available options

  • --help or -h - Print this help
  • --version or -v - Print the current version
  • --noclipboard or -n - Do not copy the URL to clipboard (default: false)
  • --quiet or -q - Suppress output when executing commands (default: false)
  • --website or -w - Set uploaded folder as a static website (default: false)
  • --spa - Set uploaded folder as a single page app (default: false)
  • --source or -s - Source of the folder that will be uploaded (default: current folder)
  • --bucket or -b - Name of the S3 bucket (default: name of the current folder)
  • --prefix or -p - Prefix on the S3 bucket (default: the root of the bucket)
  • --region or -r - AWS region where the files will be uploaded, default: saved region if exists or a list to choose one if it is not saved yet
  • --force or -f - Update the bucket without asking (default: false, forced region can be overridden with -r)
  • --update or -u - Update existing bucket (default: false)
  • --delete or -d - Delete existing bucket (default: false)
  • --nocdn or -c - Disable Cloudfront handling (default: false)
  • --urlonly or -o - Only output the resulting URL, CDN or S3 according to options (default: false)
  • --expire or -e - delete objects on bucket older than n days (default: no expiration)
  • --profile or -a - AWS profile to be used (default: 'default')
  • --empty or -y - Empty the bucket (Delete all objects before upload files) (default: false)

Examples

Create React App application

Full tutorial: http://medium.com/@slobodan/single-command-deployment-for-single-page-apps-29941d62ef97

To deploy CRA apps simply run npm run build in your project root folder to create build version.

Then deploy build version using following command:

scotty --spa --source ./build

Or, if you want to specify bucket name run:

scotty --spa --source ./build --bucket some-bucket-name

With --spa flag, Scotty will set required redirects for your single page app, so your app can use pushState out of the box.

Shared bucket application

To deploy multiple apps to a single bucket you can make use of the --prefix option. This comes in handy when your CI system deploys to a staging system with each branch as a pathname. Eg. the master branch should go to bucket root (/), so you do not set the prefix. The feature/fancy-stuff branch should go to the bucket path feature/fancy-stuff so just add this as the prefix. Here comes a command line example:

# deploy your master branch build to bucket root
scotty --source ./build --bucket some-bucket-name
# deploy your branch build to the branch name on the bucket
scotty --source_ ./build --bucket some-bucket-name --prefix your/branch

Test

We use Jasmine for unit and integration tests. Unless there is a very compelling reason to use something different, please continue using Jasmine for tests. The existing tests are in the spec folder. Here are some useful command shortcuts:

Run all the tests:

npm test

Run only some tests:

npm test -- filter=prefix

Get detailed hierarchical test name reporting:

npm test -- full

License

MIT -- see LICENSE

scottyjs's People

Contributors

asponda avatar fregante avatar jack12816 avatar luanmuniz avatar notatestuser avatar simalexan avatar stojanovic avatar suda86 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scottyjs's Issues

Improper url provided for eu-west-2 region

Creating a website in the eu-west-2 region provides the following url from scotty, http://<bucket-name>.s3-website-eu-west-2.amazonaws.com, but this doesn't work. Looking on the S3 console, the url should be http://<bucket-name>.s3-website.eu-west-2.amazonaws.com.

It seems like the simple fix would be to print the url with a . in place of the -, since it appears all regions support the first syntax, while only some support the latter.

CNAME support

Hi,

Thanks for a great tool! I wrote very similar one and I would like to send PR for some things that I don't see like CNAME support. Are you planning to add this? Is it ok if I work on it?

Configure credentials via command line. Proposal

Example:

scotty --spa --source ./build --access-key-id AKIAIOSFODNN7EXAMPLE --secret-access-key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

or

scotty --spa --source ./build --config ./scotty-config.json

scotty-config.json:

{
     "region": "<region>",
     "access-key-id": "<key>",
     "secret-access-key": "<key>"
}

And use AWS.config.loadFromPath or new AWS.Config(options) according to define credential style

PR #19 broke standard AWS credential provider chaining

PR #19 inadvertently has broken the normal AWS provider chaining described at https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

Steps to reproduce:

  1. Ensure that you have no ~/.aws/credentials file
  2. Set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to known good values
  3. Run a scotty command to communicate with s3. I used: scotty -s <dir> -b <bucket-name> -u -r <region>

Expected results:

Output similar to the following (works with v 1.9 and below):

   bucket โœค <bucket-name>
   upload โœค completed (195.81Kb, 0.81s)

Successfully beamed up! http://<bucket-name>.s3.amazonaws.com/
This link should be copied to your clipboard now.

CDN URL: null
CloudFront is super slow, this link should be valid in next 10 minutes or so.

Actual Results:

Set AWS credentials first. Guide is available here: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

Unfortunately, this ends up breaking our CI system, where there are no config files contain credentials, only secret environment variables that are only set when the CI job runs.

Recommended action(s):

AWS' provider chain allows one to actually specify the profile to use in the ~/.aws/credentials file by setting the environment variable AWS_PROFILE. For example, to use the profile named dev, add the following to the ~/.aws/credentials file:

[dev]
AWS_ACCESS_KEY_ID=<access-key>
AWS_SECRET_ACCESS_KEY=<secret-key>

Then set the environment variable and run scotty:

export AWS_PROFILE=dev
scotty -s <dir> -b <bucket-name> -u -r <region>

If this behavior was the original intent of PR #19, then the PR can simply be reverted (this is actually how I had been running scotty on my local machine for a while now).

Alternatively, if the above was not the intent of the original PR, then a code guard can be added to the setAWSProfile function of bin/scotty.js to only execute the code in that function if and only if the --profile argument is passed to the application (I can submit a PR for this if needed).

Unnecessary spaces are in "AVAILABLE OPTIONS" in help page

Summary

I found unnecessary spaces are in "AVAILABLE OPTIONS" in help page. I attached the screenshot about this.
screenshot

What is expected

I think extra spaces should be deleted.

How to reproduce

  1. Run scotty -h command

Versions

soctty version: 1.10.2
node: 8.11.1

Add verbose mode or something like it

It seems like uploads lately either are very slow or even stall completely. This is happening to me from lots of different networks. This is what I see when that happens:

screen shot 2019-01-30 at 10 08 58 pm

It would be great if we could run scotty with a verbose mode to see details about these errors.

Clear bucket before upload files

Hi! I added a new parameter to clear the bucket before upload files. Can I submit a pull request?

Thanks for Scotty tool , it has increased my productivity.

Feature: define credentials with env variables

I see on the version 2.0 roadmap that there are updates planned for the AWS credential management process overall, but I wanted to call attention to an immediate issue I'm having with the current version: Scotty.js doesn't work with CircleCI 2.0.

There's currently a bug on Circle's end where AWS credentials are not getting added to ~/.aws/credentials. Most people are using the aws CLI and can therefore work around it by passing their credentials as build environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

After digging into the scotty source code a bit, it looks like the AWS.SharedIniFileCredentials class that's getting used under the hood only looks for credentials at ~/.aws/credentials and doesn't check for credentials in any of the other config settings defined here under "Configuration Settings and Precedence".

I realize this is a bug on Circle's end and not on this repo, but I just wanted to call it out since it's forcing me to drop Scotty.js. I have never used the AWS JS SDK but will try to find an alternative to SharedIniFileCredentials that will support my use case later this week.

Issue while installing scottyjs

abhishek@edgeitadmin-Latitude-E5450:~$ scotty {options}

events.js:163
throw er; // Unhandled 'error' event
^
OpenError: IO error: tmp/.scotty-db/LOCK: No such file or directory
at /usr/local/lib/node_modules/scottyjs/node_modules/levelup/lib/levelup.js:117:34
at /usr/local/lib/node_modules/scottyjs/node_modules/abstract-leveldown/abstract-leveldown.js:39:16
abhishek@edgeitadmin-Latitude-E5450:~$ scotty

events.js:163
throw er; // Unhandled 'error' event
^
OpenError: IO error: tmp/.scotty-db/LOCK: No such file or directory
at /usr/local/lib/node_modules/scottyjs/node_modules/levelup/lib/levelup.js:117:34
at /usr/local/lib/node_modules/scottyjs/node_modules/abstract-leveldown/abstract-leveldown.js:39:16
abhishek@edgeitadmin-Latitude-E5450:$ npm -v
4.2.0
abhishek@edgeitadmin-Latitude-E5450:
$ node -v
v7.8.0
abhishek@edgeitadmin-Latitude-E5450:~$

deploy doesn't work in docker context

๐Ÿ’ฅ Beam up failed ๐Ÿ’ฅ
xsel: Can't open display: (null)
: Inappropriate ioctl for device

Docker base image is: node:8.4
scotty -w -r us-east-1 -f

Also the -r option on an initial run doesn't work, it will every time deploy to eu-central-1

Version 2 roadmap + questions and ideas

If you are using Scotty.js I would like to know what do you like and what should be improved. Feel free to comment bellow.

We started working on version 2 that will have breaking changes. This is a description of what can you expect in v2.

Scotty.js, version 2

Scotty v1 was a MVP, our goal was to see if it can be useful to us and anyone else. Now that it has some traction, it's time to fix it up :)

Version 2 features

Here's the initial version 2 features that we will work on. This list is not final. Feel free to give us feedback on v1 and tell us what would you like to see in v2.

  1. Running Scotty command first time will create scotty.json file with all the options. This file will allow us to share Scotty projects, ie. if you commit this file with your repository, anyone with AWS permissions can simply run the scotty command to deploy the app.
  2. create, update and destroy commands will be added. Running the scotty command will run scotty create or scotty update depending on scotty.json file existence.
  3. Proper destroy command will be available. It will destroy the S3 bucket and CloudFront distribution if they were created by Scotty.
  4. Custom domains feature. We have PR for that right now, but it's not finished, version 2 should have that integrated.
  5. Clearing CloudFront cache on the update.
  6. Support for multiple versions (ie. dev, staging and production).
  7. Support for SSL certificate for custom domains
  8. TBA

GZip files

Nice tool!

Given that S3 does not compress assets served from the bucket it would be very handy to have a switch to pre compress uploaded assets to S3.

Invalidating Cloudfront Cache

Hi,

Thanks for building this - really liking it so far!

I've set up Scotty to continually deploy on every git commit using Gitlab. The command is executing successfully, but my assets are never fresh :-(.

Can you point me in the right direction? Is there a built-in solution to this problem, or should I write my own solution using S3 client libraries?

Thanks in advance,

Michael

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.