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

Deployment bm #527

Open
wants to merge 73 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
0980121
Update README.md
LilachD Nov 14, 2023
943e05b
update models and PostController.create with matching test updates
LilachD Nov 14, 2023
7966768
Merge pull request #1 from LilachD/add-username-to-user-model
LilachD Nov 14, 2023
f95619c
Create node.js.yml
LilachD Nov 15, 2023
6d7445d
add mongodb action
LilachD Nov 15, 2023
b713e9b
add cypress action
LilachD Nov 15, 2023
455d02c
update npm start command to start:test
LilachD Nov 15, 2023
cbf609f
update npm start:test command to npm run start:test
LilachD Nov 15, 2023
da649d4
Merge pull request #3 from LilachD/testing-workflow-1
LilachD Nov 15, 2023
bd1c862
update workflow file name
LilachD Nov 15, 2023
761a501
update homepage title
LilachD Nov 15, 2023
2687059
fix homepage title
LilachD Nov 15, 2023
507f9e9
Merge pull request #4 from LilachD/testing-workflow
LilachD Nov 15, 2023
c61a598
separate build and test jobs
LilachD Nov 15, 2023
469d30b
undo build and test separation
LilachD Nov 15, 2023
1879793
add deploy workflow file"
LilachD Nov 15, 2023
c9a6c81
update deploy.yml
LilachD Nov 16, 2023
067d5fc
Merge pull request #5 from LilachD/deploy-workflow
LilachD Nov 16, 2023
772fdb1
adding pr.merged == false condition for build and test ci
LilachD Nov 16, 2023
5d40219
Merge pull request #6 from LilachD/deploy-workflow
LilachD Nov 16, 2023
e47d71e
update test workflow if statement and deploy workflow workflow_run
LilachD Nov 16, 2023
541ca01
Merge pull request #7 from LilachD/deploy-workflow
LilachD Nov 16, 2023
7528cf1
remove push to main trigger on test workflow
LilachD Nov 16, 2023
e2fcf54
Merge pull request #8 from LilachD/deploy-workflow
LilachD Nov 16, 2023
9e5580b
update if statement in test workflow
LilachD Nov 16, 2023
9ff6f6a
Merge pull request #9 from LilachD/deploy-workflow
LilachD Nov 16, 2023
bb1d237
update if statement in test workflow
LilachD Nov 16, 2023
cfa49e8
Merge pull request #10 from LilachD/deploy-workflow
LilachD Nov 16, 2023
7882973
small change to echo command in deploy.yml for testing purposes
LilachD Nov 16, 2023
64b0918
change deploy trigger to push to main
LilachD Nov 16, 2023
e72b188
Merge pull request #11 from LilachD/deploy-workflow
LilachD Nov 16, 2023
e5134f5
change deploy workflow echo command
LilachD Nov 16, 2023
48b583e
change deploy workflow echo command
LilachD Nov 16, 2023
08ecb96
change deploy workflow echo command
LilachD Nov 16, 2023
dab96c7
update deployment workflow
LilachD Nov 16, 2023
2e547f3
add zip and copy to s3 bucket to deploy workflow
LilachD Nov 17, 2023
51a25fd
Merge pull request #12 from LilachD/deploy-workflow-lil
LilachD Nov 17, 2023
8e32eb7
fix wrong secret names
LilachD Nov 17, 2023
ec7c5fa
Merge pull request #13 from LilachD/deploy-workflow-lil
LilachD Nov 17, 2023
46b150a
fix s3 bucket destination
LilachD Nov 17, 2023
4b916f9
Merge pull request #14 from LilachD/deploy-workflow-lil
LilachD Nov 17, 2023
29fc9c4
add deploy to CodeDeploy step in cd workflow
LilachD Nov 17, 2023
d48a055
Merge pull request #15 from LilachD/deploy-workflow-lil
LilachD Nov 17, 2023
5b5aaaa
add ! to homepage greet
LilachD Nov 17, 2023
14f4a9f
Merge pull request #16 from LilachD/deploy-workflow-lil
LilachD Nov 17, 2023
cc4ad50
add ecosystem.config.js
LilachD Nov 17, 2023
40f1548
Adds appspec.yml file in the root directory
Bereketmebrahtu Nov 17, 2023
0dc73cd
Merge pull request #17 from LilachD/deploy-workflow-lil
BmebRah Nov 17, 2023
b7d12f9
fix persmissions in appspec.yml
Bereketmebrahtu Nov 17, 2023
ad5256e
Merge pull request #18 from LilachD/deploy-workflow-lil
BmebRah Nov 17, 2023
42a0675
fix appspec file
Bereketmebrahtu Nov 17, 2023
ea2e782
Merge pull request #19 from LilachD/deploy-workflow-lil
BmebRah Nov 17, 2023
4fb60ac
update appscript user
Bereketmebrahtu Nov 17, 2023
c7e4a9d
Merge pull request #20 from LilachD/deploy-workflow-lil
BmebRah Nov 17, 2023
9618879
update appspec ami name
Bereketmebrahtu Nov 17, 2023
54f2840
Merge pull request #21 from LilachD/deploy-workflow-lil
BmebRah Nov 17, 2023
40aee13
add script to start server
LilachD Nov 17, 2023
c30b559
Merge branch 'main' into deploy-app-on-ec2
LilachD Nov 17, 2023
dbf9c1a
Merge pull request #22 from LilachD/deploy-app-on-ec2
LilachD Nov 17, 2023
0b63b8a
add npm ci to deploy, remove npm build from build-test
LilachD Nov 17, 2023
897673a
Merge pull request #23 from LilachD/changes-to-workflows
LilachD Nov 17, 2023
1f38dcb
change workflow triggers and node version
LilachD Nov 20, 2023
03c93c5
Merge pull request #24 from LilachD/changes-to-workflows
LilachD Nov 20, 2023
d6d3748
update deploy trigger
LilachD Nov 20, 2023
ffa5f20
Merge pull request #25 from LilachD/deploy-trigger
LilachD Nov 20, 2023
7cd3262
correct deploy job name
LilachD Nov 20, 2023
c3c5e44
Merge pull request #26 from LilachD/deploy-trigger
LilachD Nov 20, 2023
e06760f
add nvm+npm commands to start-server script
LilachD Nov 20, 2023
692c385
Merge pull request #27 from LilachD/start-server-script
LilachD Nov 20, 2023
aa311c1
update bin/www and node version in workflow files
LilachD Nov 20, 2023
5c0b809
Merge pull request #29 from LilachD/start-server-script
LilachD Nov 20, 2023
d5dc8b7
test
Bereketmebrahtu Nov 22, 2023
da0b569
testing
Bereketmebrahtu Nov 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build and Test

on:
push:


jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.1]
mongodb-version: ['6.0']

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.10.0
with:
mongodb-version: ${{ matrix.mongodb-version }}

- name: Cypress run
uses: cypress-io/github-action@v6
with:
start: npm run start:test
wait-on: http://localhost:3030


58 changes: 58 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Deploy

on:
workflow_run:
workflows: ['Build and Test']
branches: [main]
types: [completed]


env:
AWS_REGION: "eu-west-2"
BUCKET_NAME: "b-l-acebook-bucket"
CODEDEPLOY_APP_NAME: "b-l-acebook"
CODEPLOY_DEPLOYMENT_GROUP: "b-l-acebook-deploy"

jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

strategy:
matrix:
node-version: [18.1]

steps:
- uses: actions/checkout@v3

- name: Set up AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_SECRET_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci

- name: Zip project
run: |
zip -r b-l-acebook-app.zip .

- name: Upload to S3
run: |
aws s3 cp b-l-acebook-app.zip s3://${{ env.BUCKET_NAME }}/

- name: Deploy to CodeDeploy
run: |
aws deploy create-deployment \
--application-name ${{ env.CODEDEPLOY_APP_NAME }} \
--deployment-group-name ${{ env.CODEPLOY_DEPLOYMENT_GROUP}} \
--s3-location bucket=${{ env.BUCKET_NAME }},key=b-l-acebook-app.zip,bundleType=zip



2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It uses:

## Card wall

REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL
https://trello.com/b/LTthkPOI/acebook-bl

## Quickstart

Expand Down
18 changes: 18 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user/aws-codedeploy
permissions:
- object: /home/ec2-user
owner: ec2-user
group: ec2-user
type:
- directory
- file
hooks:
ApplicationStart:
- location: scripts/start-server.sh
timeout: 300
runas: ec2-user

2 changes: 1 addition & 1 deletion bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ function onListening() {
var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
console.log("Now listening on " + bind);
debug("Listening on " + bind);
}
}
4 changes: 3 additions & 1 deletion controllers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const PostsController = {
res.render("posts/new", {});
},
Create: (req, res) => {
const post = new Post(req.body);
const message = req.body.message;
const author = req.session.user.username;
const post = new Post({message, author});
post.save((err) => {
if (err) {
throw err;
Expand Down
3 changes: 2 additions & 1 deletion controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ const User = require("../models/user");

const UsersController = {
New: (req, res) => {
res.render("users/new", {});
res.render("users/new", { title: "Acebook" });
},

Create: (req, res) => {
const user = new User(req.body);
console.log('user:', user)
user.save((err) => {
if (err) {
throw err;
Expand Down
1 change: 1 addition & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
video: true,
e2e: {
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/user_can_see_posts_count_on_post.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ describe("Timeline", () => {
it("can see likes count on a new post", () => {
// sign up
cy.visit("/users/new");
cy.get("#username").type("someone");
cy.get("#email").type("someone@example.com");
cy.get("#password").type("password");
cy.get("#submit").click();
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/user_can_sign_in.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ describe("Authentication", () => {
it("A user signs in and is redirected to /posts", () => {
// sign up
cy.visit("/users/new");
cy.get("#username").type("someone");
cy.get("#email").type("someone@example.com");
cy.get("#password").type("password");
cy.get("#submit").click();
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/user_can_sign_up.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ describe("Registration", () => {
it("A user signs up and is redirected to sign in", () => {
// sign up
cy.visit("/users/new");
cy.get("#username").type("someone");
cy.get("#email").type("someone@example.com");
cy.get("#password").type("password");
cy.get("#submit").click();
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/user_can_submit_posts.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ describe("Timeline", () => {
it("can submit posts, when signed in, and view them", () => {
// sign up
cy.visit("/users/new");
cy.get("#username").type("someone");
cy.get("#email").type("someone@example.com");
cy.get("#password").type("password");
cy.get("#submit").click();
Expand Down
14 changes: 14 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

module.exports = {
apps: [
{
name: 'aws-codedeploy',
script: 'npx',
args: 'serve -s build -l 3000 -n',
interpreter: 'none',
env: {
NODE_ENV: 'development',
},
},
]
}
1 change: 1 addition & 0 deletions models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const mongoose = require("mongoose");

const PostSchema = new mongoose.Schema({
message: String,
author: String,
likes: { type: Number, default: 0 }
});

Expand Down
1 change: 1 addition & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mongoose = require("mongoose");

const UserSchema = new mongoose.Schema({
username: String,
email: String,
password: String,
});
Expand Down