Skip to content

Test pull request #840

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

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
38121f6
add: README and first hello.yml for github actions
juandavid015 Dec 1, 2023
43641d1
add: new production pipeline (CI/CD flow
juandavid015 Dec 1, 2023
26f85c1
update: correcting lint issues
juandavid015 Dec 1, 2023
09039db
update: CI/CD pipeline with test and build job
juandavid015 Dec 1, 2023
f241dfa
update: fix eslint linkebreak to CRLF
juandavid015 Dec 1, 2023
2a759f0
add: simple e2e test with cypress
juandavid015 Dec 11, 2023
172e41f
fix: code formatt problems for related cypress files
juandavid015 Dec 11, 2023
e939cee
add: remote deploy configuration
juandavid015 Dec 19, 2023
8c44136
update: eslint escape to index.js deprecation error message
juandavid015 Dec 19, 2023
a141fb1
update: change port to 8080
juandavid015 Dec 19, 2023
1a608f5
update: port 8080 on pipeline.yml
juandavid015 Dec 19, 2023
1be6660
add: dummy code for testing if deploy notice when application breaks
juandavid015 Dec 21, 2023
7a01f9e
add: http and tcp health check on deployment via fly.toml configuration
juandavid015 Dec 21, 2023
3236cbc
update: change interval for http checks on fly.toml
juandavid015 Dec 21, 2023
8ba5b61
update: changes on fly.toml
juandavid015 Dec 21, 2023
645b967
update fly.toml
juandavid015 Dec 21, 2023
f0b50fd
update: fly.toml
juandavid015 Dec 21, 2023
a7646be
update fly.toml
juandavid015 Dec 21, 2023
d0e23e0
update: removing forced error from app.js for health check
juandavid015 Dec 21, 2023
bfc9bc1
add: health_check.sh for a custom health check
juandavid015 Dec 22, 2023
7da3394
update: health_check.sh to be included on fly config
juandavid015 Dec 22, 2023
50a5634
update: restoring to prev config on fly.toml; custom health check not…
juandavid015 Dec 22, 2023
dc81d01
fix: fly.toml file to add new lines that solve problem with http requ…
juandavid015 Jan 1, 2024
2198530
update: pipeline workflow to work also on pull request (avoiding deploy)
juandavid015 Jan 2, 2024
8717c53
update: forcing error on app.js for test pr on different branches
juandavid015 Jan 2, 2024
0ace6f3
update: removing forced error on app.js
juandavid015 Jan 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
"env": {
"browser": true,
"node": true,
"es6": true,
"jest/globals": true
},
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/hello.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Hello World!

on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Hello World!
run: echo "Hello World!"
- name: Date
run: date
- name: Files
run: ls -l
37 changes: 37 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Deployment pipeline

on:
push: # runs on every push to master
branches:
- master
pull_request:
branches: [master]
types: [opened, synchronize] # he workflow will run when a PR into the main branch is opened or updated.
jobs:
simple_deployment_pipeline:
runs-on: ubuntu-20.04 # the type of machine to run the job on. What do is run the job on a ubuntu machine.
steps:
- uses : actions/checkout@v3 # this is a github action that checks out the code from the repo. This makes the code available to the job.
- uses: superfly/flyctl-actions/setup-flyctl@master # Installs the flyctl CLI tool to enable deploying and managing Fly apps
- uses : actions/setup-node@v3 # this is a github action that sets up node on the machine. This makes node available to the job.
with:
node-version: '16' # this is the version of node to install on the machine.
- name: Install dependencies # this is a step that installs the dependencies of the project.
run: npm install
- name: Check code formatting # this is a step that checks the code formatting.
run: npm run eslint
- name: Tests # this is a step that runs the tests.
run: npm run test
- name: Build # this is a step that builds the project.
run: npm run build
- name: e2e tests # this is a step that runs the end to end tests.
uses: cypress-io/github-action@v5
with:
command: npm run test:e2e
start: npm run start-prod
wait-on: http://localhost:8080
- name: Deploy
if: ${{ github.event_name == 'push' }}
run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=16.20.2
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Node.js"

# Node.js app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python

# Install node modules
COPY --link package-lock.json package.json ./
RUN npm ci --include=dev

# Copy application code
COPY --link . .

# Build application
RUN npm run build

# Remove development dependencies
RUN npm prune --omit=dev


# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "npm", "run", "start" ]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ This repository is used for the CI/CD module of the Full stack open course

Fork the repository to complete course exercises

### Some common steps in a CI setup include linting, testing, and building. What are the specific tools for taking care of these steps in the ecosystem of the language you picked?
In python, for linting: "flake8" or "pylint". In testing, pytest or unittest. Building: "setuptools" or "wheel"

### What alternatives are there to set up the CI besides Jenkins and GitHub Actions?
Buddy, a faster, simpler, and more reliable Jenkins alternative. Also others like: Azure pipelines, Bamboo by Atlassian, gitlab CI/CD.

### Would this setup be better in a self-hosted or a cloud-based environment? Why? What information would you need to make that decision?
Depends on the project and complexity, on a large and robust infrastructure, the more situable solution would be a self-hosted one. Otherwise,
for a more small, personal project, the less configuration the better, so, cloud-based solution. Also, even between languages, there's not seem
much difference on the linting, building and testing, just tools and probably some configuration, but the process concept may keep the same.
## Commands

Start by running `npm install` inside the project folder
Expand Down
22 changes: 16 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
const express = require("express");
const app = express();
const express = require('express')
const app = express()

// Heroku dynamically sets a port
const PORT = process.env.PORT || 5000;
const PORT = process.env.PORT || 8080

app.use(express.static("dist"));
app.use(express.static('dist'))

app.get('/health', (req, res) => {
// throw new Error('error...')
// eslint-disable-next-line no-unreachable
res.send('ok')
})

app.get('/version', (req, res) => {
res.send('1') // change this string to ensure a new version deployed
})
app.listen(PORT, () => {
console.log("server started on port 5000");
});
// eslint-disable-next-line no-console
console.log('server started on port 8080')
})
9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
e2e: {
setupNodeEvents() {
// implement node event listeners here
},
},
})
15 changes: 15 additions & 0 deletions cypress/e2e/pokemon_app.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint disable no-undef for this file
/* eslint-disable no-undef */
describe('Pokedex', function() {
it('front page can be opened', function() {
cy.visit('http://localhost:8080')
cy.contains('ivysaur')
cy.contains('Pokémon and Pokémon character names are trademarks of Nintendo.')
})
it('pokemon page can be navigated to', function() {
cy.visit('http://localhost:8080')

cy.contains('ivysaur').click()
cy.contains('chlorophyll')
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
56 changes: 56 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# fly.toml app configuration file generated for full-stack-open-pokedex-cicd on 2024-01-01T17:38:36-05:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "full-stack-open-pokedex-cicd"
primary_region = "iad"

[experimental]
auto_rollback = true

[build]
[build.args]
NODE_VERSION = "16.20.2"

[deploy]
release_command = "npm run build"

[processes]
app = "node app.js"

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]

[[services]]
protocol = "tcp"
internal_port = 8080
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]

[[services.tcp_checks]]
interval = "15s"
timeout = "2s"
grace_period = "1s"

[[services.http_checks]]
interval = "10s"
timeout = "2s"
grace_period = "5s"
method = "get"
path = "/health"
protocol = "http"
tls_skip_verify = false

[[vm]]
cpu_kind = "shared"
cpus = 1
memory_mb = 1024
processes = ["app"]
12 changes: 12 additions & 0 deletions health_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

res=$(curl -s https://full-stack-open-pokedex-cicd.fly.dev/health)

if [ "$res" == "ok" ]; then
echo "Succeeded curl to /health"
exit 0
fi

echo "Failed curl to /health"
# 0: OK, 1: Bad.
exit 1
Loading