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

Develop #232

Open
wants to merge 103 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
2c7af7a
Add Hello World GitHub Actions workflow
Oct 3, 2024
be76693
Add date and ls -l
Oct 3, 2024
a8f2756
Linting
Oct 3, 2024
04d05b5
Linting_2
Oct 3, 2024
f30bbe9
Linting_3
Oct 3, 2024
7b94545
Build and test
Oct 3, 2024
469527b
Build and test correct
Oct 3, 2024
e72b0e3
Playwright tests
Oct 4, 2024
9146b1d
Playwright tests2
Oct 4, 2024
b7905ca
Playwright tests3
Oct 4, 2024
e44c547
Playwright tests4
Oct 4, 2024
61b857d
Playwright tests5
Oct 4, 2024
1296ef4
Playwright tests6
Oct 4, 2024
384517d
Playwright tests7
Oct 4, 2024
5f4a8ba
Playwright tests8
Oct 4, 2024
9139f05
Playwright tests9
Oct 4, 2024
e898f9a
Playwright tests10
Oct 4, 2024
a133d11
Playwright tests11
Oct 4, 2024
00ff013
Playwright tests12
Oct 4, 2024
a9a2092
Deploy build
Oct 4, 2024
3da059e
Deploy build
Oct 4, 2024
36c7675
Deploy test
Oct 5, 2024
d9b0321
Deploy test health
Oct 5, 2024
a126f9a
Deploy test health is fine
Oct 5, 2024
9ccf5cc
Deploy test health is NO fine
Oct 5, 2024
2c47c17
Deploy Health
Oct 5, 2024
5ca318c
pull_request
Oct 5, 2024
0f23d3e
develop Changes
Oct 5, 2024
495a239
Changes_3
Oct 5, 2024
93a25c8
Changes main 1
Oct 5, 2024
2febaac
Changes from develop branch
Oct 5, 2024
dab1727
Merge branch 'main' into develop
lemon1964 Oct 6, 2024
292c37a
Test deploy from main
Oct 6, 2024
c24da4d
Changes_4
Oct 6, 2024
6017a3f
Merge branch 'main' into develop
lemon1964 Oct 6, 2024
05dea93
Changes_4
Oct 6, 2024
0294bf7
Changes develop_5
Oct 6, 2024
b209292
Changes main_6
Oct 6, 2024
ec27516
Changes develop_6
Oct 6, 2024
893fe1f
Merge branch 'main' into develop
lemon1964 Oct 6, 2024
e41c759
Test changes in develop
Oct 6, 2024
1feeb03
Changes develop_7
Oct 6, 2024
0d4260b
Changes develop_8
Oct 6, 2024
bcdc401
Changes develop_9 #skip
Oct 6, 2024
f1ac8d5
Changes develop_9
Oct 6, 2024
12886a1
Changes develop_10
Oct 6, 2024
067df81
Changes develop_11
Oct 6, 2024
8863098
Changes develop_12
Oct 7, 2024
ee18941
Changes develop_13
Oct 7, 2024
fa02bff
Changes develop_14
Oct 7, 2024
a1c9aad
Changes develop_15
Oct 7, 2024
5c016de
Changes develop_16
Oct 7, 2024
9581499
Changes develop_17
Oct 7, 2024
a8bcd8d
Changes develop_18
Oct 7, 2024
a698780
Changes develop_19
Oct 7, 2024
30de106
Changes develop_20
Oct 7, 2024
22c7fda
Changes develop_21
Oct 7, 2024
1b77584
Changes develop_22
Oct 7, 2024
4132292
Changes develop_23
Oct 7, 2024
ca86ac3
Changes develop_24
Oct 8, 2024
b342963
Changes develop_25
Oct 8, 2024
eeace17
Changes develop_26
Oct 8, 2024
a85949d
Changes develop_27
Oct 8, 2024
2ce98e9
Changes develop_28
Oct 8, 2024
5ee9a78
Changes develop_29
Oct 8, 2024
09f21af
Changes develop_30
Oct 8, 2024
dd0bd53
Changes develop_31
Oct 8, 2024
a3142a9
Changes develop_32
Oct 8, 2024
fe27d5c
Changes develop_33
Oct 8, 2024
0a9288e
Changes develop_34
Oct 8, 2024
1f13434
Changes develop_35
Oct 8, 2024
4d5c090
Changes develop_36
Oct 8, 2024
0c62a21
Changes
Oct 8, 2024
69608e8
Changes
Oct 8, 2024
d1724b5
Changes
Oct 8, 2024
98cc8a3
Changes
Oct 8, 2024
d96bf97
Changes
Oct 8, 2024
c66e055
Changes
Oct 8, 2024
7833b66
Changes
Oct 8, 2024
3141c69
Changes
Oct 8, 2024
be8d36a
Changes
Oct 8, 2024
e513399
Changes
Oct 8, 2024
5746734
Changes
Oct 8, 2024
d477280
Changes
Oct 8, 2024
e17e7d6
Changes
Oct 8, 2024
6311f58
Changes
Oct 8, 2024
6a7a9b1
Changes
Oct 8, 2024
239d52c
Changes
Oct 8, 2024
c61fe7b
Changes
Oct 8, 2024
72d7198
Changes
Oct 8, 2024
f4d21b1
Changes
Oct 8, 2024
fcd5a61
Changes
Oct 8, 2024
710fc1a
Changes
Oct 8, 2024
f6dd945
Changes
Oct 8, 2024
290f781
Changes
Oct 8, 2024
df44556
Changes
Oct 8, 2024
505d1f6
Changes
Oct 9, 2024
eb2db80
Changes
Oct 9, 2024
b7fc683
Changes
Oct 9, 2024
28c56af
Changes
Oct 9, 2024
cbdc239
develop Changes
Oct 14, 2024
988702f
final Pull Request
Oct 15, 2024
09fc72c
final Pull Request
Oct 15, 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
71 changes: 28 additions & 43 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,34 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"jest/globals": true
settings: {
react: {
version: 'detect' // Автоматическое определение версии React
}
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
env: {
browser: true,
es6: true,
'jest/globals': true,
node: true
},
extends: ['eslint:recommended', 'plugin:react/recommended'],
parserOptions: {
ecmaFeatures: {
jsx: true
},
"ecmaVersion": 2018,
"sourceType": "module"
ecmaVersion: 2018,
sourceType: 'module'
},
"plugins": [
"react", "jest"
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
],
"eqeqeq": "error",
"no-trailing-spaces": "error",
"object-curly-spacing": [
"error", "always"
],
"arrow-spacing": [
"error", { "before": true, "after": true }
],
"no-console": "error",
"react/prop-types": 0
plugins: ['react', 'jest'],
rules: {
indent: ['error', 2],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'never'],
eqeqeq: 'error',
'no-trailing-spaces': 'error',
'object-curly-spacing': ['error', 'always'],
'arrow-spacing': ['error', { before: true, after: true }],
'no-console': 'off',
'react/prop-types': 0
}
}
20 changes: 20 additions & 0 deletions .github/workflows/hello.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Hello World!

on:
push:
branches:
- main

jobs:
hello_world_job:
runs-on: ubuntu-20.04
steps:
- name: Say hello
run: |
echo "Hello World!"
- name: Now it is
run: |
date
- name: Directory content
run: |
ls -l
121 changes: 121 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Deployment pipeline

on:
push:
branches:
- main
pull_request:
branches: [main]
types: [opened, synchronize]

env:
SKIP_DEPLOYMENT: ${{ contains(join(github.event.commits.*.message, ' '), '#skip') }}

jobs:
simple_deployment_pipeline:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: npm install

- name: Lint
run: npm run eslint
id: lint-check

- name: Build
run: npm run build
id: build-check
continue-on-error: true

- name: Build Failure Notification
if: steps.build-check.outcome == 'failure'
run: |
BASE_URL="${{ secrets.BASE_URL }}"
WEBHOOK_PATH="${{ secrets.WEBHOOK_PATH }}"
FULL_URL="${BASE_URL}${WEBHOOK_PATH}"
CURRENT_TIME=$(date +"%Y-%m-%d %H:%M:%S")
curl -X POST -H "Content-Type: application/json" -d '{
"username": "lemon196417",
"content": "Build Failure Detected",
"embeds": [{
"title": "Build Failure",
"description": "Commit [${{ github.sha }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}) by ${{ github.actor }} broke the build. You can view the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details.",
"color": 15158332,
"footer": {
"text": "Severity: Error • '"$CURRENT_TIME"'"
}
}]
}' "$FULL_URL"

- name: Install Playwright Browsers
run: npx playwright install --with-deps

- name: Test
run: npm run test
id: test-check

- name: Run Playwright tests
run: npm run test:e2e
id: test-e2e-check

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30

- name: Trigger deployment
if: github.ref == 'refs/heads/main' && env.SKIP_DEPLOYMENT == 'false'
run: curl https://api.render.com/deploy/srv-${{ secrets.RENDER_SERVICE_ID }}?key=${{ secrets.RENDER_API_KEY }}

- name: Deploy to Render
if: github.ref == 'refs/heads/main' && env.SKIP_DEPLOYMENT == 'false'
run: |
echo "Deploying to Render"
git push https://github.com/lemon1964/full-stack-open-pokedex.git HEAD:main

- name: Send Discord Notification on Successful Deployment
if: github.ref == 'refs/heads/main' && env.SKIP_DEPLOYMENT == 'false'
run: |
BASE_URL="${{ secrets.BASE_URL }}"
WEBHOOK_PATH="${{ secrets.WEBHOOK_PATH }}"
FULL_URL="${BASE_URL}${WEBHOOK_PATH}"
CURRENT_TIME=$(date +"%Y-%m-%d %H:%M:%S")
curl -X POST -H "Content-Type: application/json" -d '{
"username": "lemon196417",
"content": "A new version of Pokedex deployed!",
"embeds": [{
"title": "Deployment Details",
"description": "Deployed to [full-stack-open-pokedex-render](https://full-stack-open-pokedex-op08.onrender.com/) by lemon1964",
"color": 3066993,
"footer": {
"text": "Severity: Informational • '"$CURRENT_TIME"'"
}
}]
}' "$FULL_URL"

- name: Log Webhook Result
run: echo "Webhook message sent successfully."


tag_release:
needs: [simple_deployment_pipeline]
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Bump version and push tag
if: github.ref == 'refs/heads/main' && env.SKIP_DEPLOYMENT == 'false'
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
WITH_V: true

20 changes: 20 additions & 0 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Schedule

on:
schedule:
- cron: '0 15 1 * *'
workflow_dispatch:

jobs:
test_schedule:
runs-on: ubuntu-20.04
steps:
- name: Check the deployed service URL
uses: jtalk/url-health-check-action@v4
with:
url: https://full-stack-open-pokedex-op08.onrender.com/health
follow-redirect: false
max-attempts: 3
retry-delay: 10s


6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
dist/
node_modules/
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"singleQuote": true,
"semi": false,
"trailingComma": "none",
"printWidth": 80,
"tabWidth": 2,
"endOfLine": "lf"
}

69 changes: 59 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,64 @@
# Full Stack open CI/CD
# Full Stack Open Course Assignments, Part 11

This repository is used for the CI/CD module of the Full stack open course
This repository contains a project from **Part 11** of the Full Stack Open course, based on the [full-stack-open-pokedex](https://github.com/fullstack-hy2020/full-stack-open-pokedex) project with a Webpack configuration. The project website features a collection of Pokemon, each with its own page containing detailed information. The project includes a full CI/CD deployment pipeline.

Fork the repository to complete course exercises
A custom **Blogs** project was implemented based on the full-stack-open-pokedex project at [https://github.com/lemon1964/Blogs.git](https://github.com/lemon1964/Blogs.git). The **blogs_backend** and **blogs_redux** projects from Part 7 of the Full Stack Open course were used as the backend and frontend templates. Both projects were placed in a shared repository under `client` and `server` folders, and the configuration files and `package.json` were refactored. Otherwise, the CI/CD deployment for the **Blogs** project is identical to that of the full-stack-open-pokedex project.

## Commands
### Project Overview and Steps

Start by running `npm install` inside the project folder
**full-stack-open-pokedex**:
- Created a production build of the project.
- Set up a workflow in the `hello.yml` file that displays a "Hello World!" message to the user.
- The main workflows in GitHub Actions are defined in the `pipeline.yml` file, described below.
- Implemented the **Lint** workflow.
- Implemented the **Build** workflow.
- Fixed jest tests and wrote end-to-end tests with Playwright.
- Created the **Test** workflow.
- Created the **Run Playwright Tests** workflow.
- Deployed the app to Render.
- Implemented auto-deployment using Render's deploy hook.
- Set up a health check at the `/health` endpoint.
- Created a new `develop` branch and opened a pull request to the `main` branch.
- Added version control automation with the **Bump version and push tag** feature.
- Configured commit messages with `#skip` to exclude deployments and mark tagged releases.
- Protected the `main` branch, requiring approval for all pull requests and passing all status checks before merging.
- Set up notifications to Discord for successful deployments and error reports in case of build failures.
- Added a **schedule.yml** file to schedule a monthly health check of the deployed app by pinging `/health`.

### How to Use

1. **Clone the repository**:
```sh
git clone https://github.com/lemon1964/full-stack-open-pokedex.git
```

2. **Install dependencies**:
```sh
npm install
```

3. **Run the project locally**:
```sh
npm run dev
```
Make sure it works at [http://localhost:8080/](http://localhost:8080/).

4. **Full Check**:
To fully check the project, you need to:
- Create a new GitHub repository.
- Configure it according to the `.yml` files provided in the project.
- Deploy the project to Render.

5. **Full-stack-open-pokedex on Render**:
You can check the deployed **Pokedex** project at [https://full-stack-open-pokedex-op08.onrender.com/](https://full-stack-open-pokedex-op08.onrender.com/).

6. **Blogs on Render**:
You can check the deployed **Blogs** project at [https://blogs-jaml.onrender.com/](https://blogs-jaml.onrender.com/).
You can log in using the following credentials:
**Username**: `admin`
**Password**: `admin`

---

If you have any questions or need additional clarification, feel free to contact us!

`npm start` to run the webpack dev server
`npm test` to run tests
`npm run eslint` to run eslint
`npm run build` to make a production build
`npm run start-prod` to run your production build
21 changes: 15 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
const express = require("express");
const app = express();
const express = require('express')
const app = express()

app.get('/health', (req, res) => {
res.send('Health is fine!')
})
// app.get('/health', (req, res) => {
// // eslint-disable-next-line no-constant-condition
// if (true) throw('error... ')
// res.send('ok')
// })

// get the port from env variable
const PORT = process.env.PORT || 5000;
const PORT = process.env.PORT || 5000

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

app.listen(PORT, () => {
console.log(`server started on port ${PORT}`);
});
console.log(`server started on port ${PORT}`)
})
5 changes: 5 additions & 0 deletions build_step.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo "Build script"
npm install
npm run build
13 changes: 13 additions & 0 deletions exercise1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**CI/CD for Python Applications**

When setting up a CI/CD pipeline for Python applications, the key steps are linting, testing, and building. There are several popular tools in the Python ecosystem for each of these steps.

- **Linting**. For static code analysis in Python, a commonly used tool is `Flake8`, which checks the code for compliance with PEP 8, the Python style standard. You can also use `Pylint`, which provides more detailed reports on the quality of the code.
- **Testing**. For automated code testing in Python, `pytest` and `unittest` libraries are popular. They allow you to run tests, and also integrate with various CI platforms to run tests automatically on each commit.
- **Build**. Building an application involves preparing distributions or containers for deployment. In Python, you can use `setuptools` to create packages, and Docker to containerize the application.

Alternatives for setting up CI/CD include CircleCI, TravisCI, and GitLab CI. CircleCI works particularly well with Docker and parallel builds, which can speed up your pipeline. TravisCI integrates with GitHub and offers free plans for open-source projects. GitLab CI is a built-in solution for GitLab users, making it an attractive option for those who use the platform for source control.

Choosing between an on-premises or cloud CI/CD environment depends on a number of factors. Cloud-based solutions, such as GitHub Actions or CircleCI, simplify the setup process and provide the scalability of the cloud, which is especially useful for team collaboration. On-premises solutions can be useful for proprietary or mission-critical applications that require full control of the environment. However, they require more resources and time to maintain the infrastructure.

To make a decision, you need to weigh your security requirements, maintenance costs, and scalability. If the team is small and the project does not require specific conditions, cloud solutions will be preferable.
Loading