diff --git a/.github/aws-config.yml.remove b/.github/aws-config.yml.remove new file mode 100644 index 00000000..49fc82dd --- /dev/null +++ b/.github/aws-config.yml.remove @@ -0,0 +1,42 @@ + +########################################################## +# AWS Configuration file for NodeJS Deploy GitHub Action # +# # +# NOTE: This file holds the variables needed # +# to configure the GitHub Deploy NodeJS # +# on AWS Serverless # +# # +# This file needs to be in the location: # +# - .github/aws-config.yml # +# in your repository to be parsed at run time # +########################################################## + +######################################## +# AWS S3 Bucket for package and deploy # +######################################## +# NOTE: This bucket must exist before the GitHub Action, and match the name of your S3 bucket on Amazon +#s3_bucket: crest-github-cd/{datetime}.zip + +################################## +# AWS Cloud Formation Stack name # +################################## +# NOTE: Defaults to "mystack" if left empty +aws_stack_name: mystack + +#################### +# AWS SAM Template # +#################### +# NOTE: This is the AWS SAM template.yml file that we need to deploy +# Pathing is from root of repository: +# Example: +# if file is called `template.yml` and is in the root of repository +# under the '.github' folder: +# sam_template: .github/template.yml +sam_template: sam-template.yml + +################################ +# region for connection to AWS # +################################ +# Default region is: us-west-2 +# if not provided below +region: ap-southeast-1 diff --git a/.github/workflows/aws.yml.backuo b/.github/workflows/aws.yml.backuo new file mode 100644 index 00000000..f4c445a3 --- /dev/null +++ b/.github/workflows/aws.yml.backuo @@ -0,0 +1,67 @@ +# This workflow will build and push a new container image to Amazon ECR, +# and then will deploy a new task definition to Amazon ECS, when a release is created +# +# To use this workflow, you will need to complete the following set-up steps: +# +# 1. Create an ECR repository to store your images. +# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`. +# Replace the value of `ECR_REPOSITORY` in the workflow below with your repository's name. +# Replace the value of `aws-region` in the workflow below with your repository's region. +# +# 2. Create an ECS task definition, an ECS cluster, and an ECS service. +# For example, follow the Getting Started guide on the ECS console: +# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun +# Replace the values for `service` and `cluster` in the workflow below with your service and cluster names. +# +# 3. Store your ECS task definition as a JSON file in your repository. +# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`. +# Replace the value of `task-definition` in the workflow below with your JSON file's name. +# Replace the value of `container-name` in the workflow below with the name of the container +# in the `containerDefinitions` section of the task definition. +# +# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. +# See the documentation for each action used below for the recommended IAM policies for this IAM user, +# and best practices on handling the access key credentials. + +on: + pull_request: + branches: + - master + +name: Deploy to Amazon ECS + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: npm install and build webpack + run: | + npm audit fix + npm install + + - uses: actions/upload-artifact@master + with: + name: webpack artifacts + path: dist/ + + deploy: + name: Deploy Node.js app to AWS + needs: build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Download built artifact + uses: actions/download-artifact@master + with: + name: webpack artifacts + path: public + + - name: Deploy to AWS + uses: github/deploy-nodejs@master + env: + AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/aws_s3.yml.remove b/.github/workflows/aws_s3.yml.remove new file mode 100644 index 00000000..c5ad5928 --- /dev/null +++ b/.github/workflows/aws_s3.yml.remove @@ -0,0 +1,69 @@ +# This workflow will build and push a new container image to Amazon ECR, +# and then will deploy a new task definition to Amazon ECS, when a release is created +# +# To use this workflow, you will need to complete the following set-up steps: +# +# 1. Create an ECR repository to store your images. +# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`. +# Replace the value of `ECR_REPOSITORY` in the workflow below with your repository's name. +# Replace the value of `aws-region` in the workflow below with your repository's region. +# +# 2. Create an ECS task definition, an ECS cluster, and an ECS service. +# For example, follow the Getting Started guide on the ECS console: +# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun +# Replace the values for `service` and `cluster` in the workflow below with your service and cluster names. +# +# 3. Store your ECS task definition as a JSON file in your repository. +# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`. +# Replace the value of `task-definition` in the workflow below with your JSON file's name. +# Replace the value of `container-name` in the workflow below with the name of the container +# in the `containerDefinitions` section of the task definition. +# +# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. +# See the documentation for each action used below for the recommended IAM policies for this IAM user, +# and best practices on handling the access key credentials. + +on: + push: + branches: + - master + +name: Deploy to Amazon ECS + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: npm install and build webpack + run: | + npm audit fix + npm install + + - uses: actions/upload-artifact@master + with: + name: webpack artifacts + path: dist/ + + deploy: + name: Deploy Node.js app to AWS + needs: build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Download built artifact + uses: actions/download-artifact@master + with: + name: webpack artifacts + path: public + + - name: Deploy to AWS + uses: github/deploy-nodejs@master + env: + AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_S3_BUCKET: crest-github-cd/aws-github-prod.zip + AWS_REGION: ap-southeast-1 diff --git a/.github/workflows/copyFileToServer.yml b/.github/workflows/copyFileToServer.yml new file mode 100644 index 00000000..0319c767 --- /dev/null +++ b/.github/workflows/copyFileToServer.yml @@ -0,0 +1,50 @@ +name: scp copy folder to remote via SSH + +on: + push: + branches: [ Devlopment ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: checkout1 + uses: actions/checkout@v1 + - name: Removeing the old distribution + uses: garygrossgarten/github-action-ssh@release + with: + command: | + cd /opt/tonkotsu-nodejs + killall node + rm -rf * + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + env: + CI: true + - name: Copy folder content recursively to remote + uses: garygrossgarten/github-action-scp@release + with: + local: "." + remote: "/opt/tonkotsu-nodejs" + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + env: + CI: true + + - name: Install the module and Run stagging server + uses: garygrossgarten/github-action-ssh@release + with: + command: | + cd /opt/tonkotsu-nodejs + npm install + npm start /dev/null & + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + env: + CI: true + + diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 00000000..39fcd1aa --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,29 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ Devlopment ] + pull_request: + branches: [ Devlopment ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x, 14.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run build --if-present + - run: npm test diff --git a/.github/workflows/node.js.yml.remove b/.github/workflows/node.js.yml.remove new file mode 100644 index 00000000..39fcd1aa --- /dev/null +++ b/.github/workflows/node.js.yml.remove @@ -0,0 +1,29 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ Devlopment ] + pull_request: + branches: [ Devlopment ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x, 14.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run build --if-present + - run: npm test diff --git a/.github/workflows/nodejs.yml.remove b/.github/workflows/nodejs.yml.remove new file mode 100644 index 00000000..fd1ecaf1 --- /dev/null +++ b/.github/workflows/nodejs.yml.remove @@ -0,0 +1,31 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [devlopment ] + pull_request: + branches: [devlopment ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run build --if-present + - run: npm test + env: + CI: true diff --git a/.github/workflows/nodejs_1.yml,backup b/.github/workflows/nodejs_1.yml,backup new file mode 100644 index 00000000..4390e930 --- /dev/null +++ b/.github/workflows/nodejs_1.yml,backup @@ -0,0 +1,31 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run build --if-present + - run: npm test + env: + CI: true diff --git a/README.md b/README.md index e02cd858..7d566440 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,14 @@ This repository contains the base project part of our on-site GitHub Verified Partner workshop program. It is meant to be used for in-classroom training under the supervision of GitHub coaches. -This is the NodeJS version of our "Tonkotsu" workshop webapp. The codebase is pretty simple: it's a NodeJS app that will connect to GitHub's [Octocat API endpoint](https://api.github.com/octocat) and return the Zen quote of the day. E.g.: +This is the NodeJS version of our "Tonkotsu" workshop webapp. The codebase is pretty simple: it's a NodeJS app that will connect to GitHub's [Octocat API endpoint](https://api.github.com/octocat) and return the Zen quote of the day. E.g ### Demo (sucess) ![out](https://user-images.githubusercontent.com/1078545/57860397-bc7ff380-77ec-11e9-80f8-39e02ef3c035.gif) -### Demo (failure) +### Demo (failure)# ![out](https://user-images.githubusercontent.com/1078545/57860396-bc7ff380-77ec-11e9-8f55-83b879e667d2.gif) @@ -30,7 +30,7 @@ Tests: ``` npm run test -``` +```'` Run server (defaults to localhost:3000): diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 00000000..cb13383b --- /dev/null +++ b/appspec.yml @@ -0,0 +1,14 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /opt/tonkotsu-nodejs/ +hooks: + BeforeInstall: + - location: deploy/before_install/before_start.sh + timeout: 300 + runas: root + AfterInstall: + - location: deploy/before_install/after_start.sh + timeout: 300 + runas: root diff --git a/deploy/after_start.sh b/deploy/after_start.sh new file mode 100644 index 00000000..327a2a5b --- /dev/null +++ b/deploy/after_start.sh @@ -0,0 +1,2 @@ +#!/bin/sh +service httpd restart diff --git a/deploy/before_install/after_start.sh b/deploy/before_install/after_start.sh new file mode 100644 index 00000000..0291f960 --- /dev/null +++ b/deploy/before_install/after_start.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +cd /opt/tonkotsu-nodejs +sudo npm install +sudo npm start /dev/null & diff --git a/deploy/before_install/before_start.sh b/deploy/before_install/before_start.sh new file mode 100644 index 00000000..28bdd73f --- /dev/null +++ b/deploy/before_install/before_start.sh @@ -0,0 +1,5 @@ +#!/bin/sh +cd /opt/tonkotsu-nodejs +killall node +rm -rf * + diff --git a/deploy/before_start.sh b/deploy/before_start.sh new file mode 100644 index 00000000..c51ca003 --- /dev/null +++ b/deploy/before_start.sh @@ -0,0 +1,4 @@ +#!/bin/sh +yum update +yum install -y httpd +service httpd start diff --git a/dist/sample.js b/dist/sample.js new file mode 100644 index 00000000..9df6e8d1 --- /dev/null +++ b/dist/sample.js @@ -0,0 +1 @@ +sampleFile diff --git a/dist/sample_node.js b/dist/sample_node.js new file mode 100644 index 00000000..9df6e8d1 --- /dev/null +++ b/dist/sample_node.js @@ -0,0 +1 @@ +sampleFile diff --git a/package-lock.json b/package-lock.json index a2937672..e9586b56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -942,7 +942,7 @@ "levn": "^0.3.0", "lodash": "^4.17.5", "minimatch": "^3.0.4", - "mkdirp": "^0.5.1", + "mkdirp": "1.0.4", "natural-compare": "^1.4.0", "optionator": "^0.8.2", "path-is-inside": "^1.0.2", diff --git a/sam-template.yml b/sam-template.yml new file mode 100644 index 00000000..1e500e5d --- /dev/null +++ b/sam-template.yml @@ -0,0 +1,52 @@ +Transform: 'AWS::Serverless-2016-10-31' +Resources: + + MainFunction: + # This resource creates a Lambda function. + Type: 'AWS::Serverless::Function' + + Properties: + + # This function uses the Nodejs v12 runtime. + Runtime: nodejs12.x + + # This is the Lambda function's handler. + Handler: handler.lambdaHandler + + # The location of the Lambda function code. + CodeUri: . + + # Event sources to attach to this function. In this case, we are attaching + # one API Gateway endpoint to the Lambda function. The function is + # called when a HTTP request is made to the API Gateway endpoint. + Events: + + MainPage: + # Define an API Gateway endpoint that responds to HTTP GET at /thumbnail + Type: Api + Properties: + Path: / + Method: GET + CSSFile: + # Define an API Gateway endpoint that responds to HTTP GET at /thumbnail + Type: Api + Properties: + Path: /public/index.css + Method: GET + JSFile: + # Define an API Gateway endpoint that responds to HTTP GET at /thumbnail + Type: Api + Properties: + Path: /public/main.js + Method: GET + +Outputs: + # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function + # Find out more about other implicit resources you can reference within SAM + # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api + StagingUrl: + Description: "Staging URL" + Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + + + diff --git a/test/utils.test.js b/test/utils.test.js index be1803c5..e9735190 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -12,7 +12,7 @@ var mochaAsync = fn => { describe("Utils", function() { describe("greetings", function() { it("Says Hello World", function() { - assert.equal(utils.greetings("World"), "Hello World 👋👋"); + assert.equal(utils.greetings("World"),"Hello World 👋👋"); }); it("Throws on missing params", function() { diff --git a/views/index.pug b/views/index.pug index e7d469fe..30bf4b97 100644 --- a/views/index.pug +++ b/views/index.pug @@ -1,18 +1,18 @@ html head style - include stylize.css + include stylize.css body header.wrap nav - a(href="#") GitHub Partners + a(href="https://crestsolution.com") Crest Infosolution .right a(href="#") Docs a(href="#") About main.wrap h1 Hello 🌎! hr - p This is our Tonkotsu 🍜 NodeJS webapp. You can find instructions inside the repository. + p This is our Tonkotsu 🍜 NodeJS webapp. You can find instructions inside the repository-demo pre #{zen.msg} footer.wrap