Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.
Open

Lab4 #1237

Show file tree
Hide file tree
Changes from all commits
Commits
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
84 changes: 84 additions & 0 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Node.js CI

on:
push:
paths:
- 'app_node/**'
- '.github/workflows/node-ci.yml'
pull_request:
paths:
- 'app_node/**'
- '.github/workflows/node-ci.yml'

defaults:
run:
working-directory: ./app_node # Set the default directory of the Node.js project

jobs:

lint-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14' # Change to your preferred Node.js version

- name: Install dependencies
run: |
npm install

- name: Lint with ESLint
run: |
npx eslint .

- name: Run tests
run: |
npx mocha test.js

security-check:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout code repository
uses: actions/checkout@v2

- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
continue-on-error: true # To make sure that SARIF upload gets called
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --all-projects --sarif

build-and-push:
needs: [lint-and-test, security-check]
runs-on: ubuntu-latest

steps:

- name: Checkout code repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
run: |
docker buildx build -t artkochergin/random-node-app:latest .
docker buildx build --push -t artkochergin/random-node-app:latest .
working-directory: ./app_node # Change to your project directory
105 changes: 105 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Python CI

on:
push:
paths:
- 'app_python/**'
- '.github/workflows/python-ci.yml'
pull_request:
paths:
- 'app_python/**'
- '.github/workflows/python-ci.yml'

defaults:
run:
working-directory: ./app_python # We set the default directory of python project

jobs:

lint-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]

steps:
- name: Checkout code repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
./app_python/requirements.txt

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Lint with flake8
run: |
pip install flake8
flake8 .

- name: Run unit tests
run: |
python test_app.py

security-check:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout code repository.
uses: actions/checkout@v3

- name: Check for vulnerabilities using Snyk
uses: snyk/actions/python-3.10@master
continue-on-error: true # To make sure that SARIF upload gets called
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args:
--package-manager=pip
--skip-unresolved
--file=app_python/requirements.txt

build-and-push:
needs: [lint-and-test, security-check]
runs-on: ubuntu-latest

steps:

- name: Checkout code repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
id: login
uses: docker/login-action@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build Docker image
run: |
docker buildx build -t artkochergin/time-python-app:latest .
docker buildx build --push -t artkochergin/time-python-app:latest .
working-directory: ./app_python # Change to your project directory

- name: Check Docker Hub Login Status
run: echo "Logged in to Docker Hub successfully."

- name: Logout from Docker Hub
run: docker logout


3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/.idea
**/venv/
**/__pycache__/
12 changes: 12 additions & 0 deletions app_node/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
env:
browser: true
commonjs: true
es2021: true
plugins:
- "mocha"
ignorePatterns:
- "**/test.js"
extends: eslint:recommended
parserOptions:
ecmaVersion: latest
rules: {}
23 changes: 23 additions & 0 deletions app_node/DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Containerization Lab

> In this .md file, I describe how I crafted the dockerfile, what best practices I used. How did I build and test an image. How did I push and pull an image, verifying and validating its functionality.

## Docker application ( `Quick Guide` )

> You can find my image on dockerhub, the link is clickable - [my-node-app](https://hub.docker.com/layers/artkochergin/my-node-app/dev/images/sha256:ae865650ef996ee89da47f6bda8182234f62f24a43d4210e96e0a2fd9db4af51)

1. **How to build?**

- Clone a repository.
- Change directory to app_python.
- Run ```docker build -t registry/name/tag .```

2. **How to pull?**

- Login in your dockerhub account.
- Run ```docker pull artkochergin/my-node-app/dev```

3. **How to run?**

- Pull or build an image first.
- Run ```docker run -p PORT:8080 artkochergin/my-node-app/dev``` instead of `PORT` specify which port you want to use**
20 changes: 20 additions & 0 deletions app_node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js runtime as a parent image
FROM node:14-alpine

# Set the working directory in the container
WORKDIR /app

# Copy all of the application files to the container
COPY . /app

# Create user and set ownership and permissions as required
RUN adduser myuser -D && chown -R myuser /app

# Pick the running user
USER myuser

# Expose the port on which your Node.js app will run
EXPOSE 3000

# Start the Node.js application
CMD ["node", "app.js"]
28 changes: 28 additions & 0 deletions app_node/NODE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Node.js Web Application
![Node-CI workflow](https://github.com/artkochergin/core-course-labs/actions/workflows/node-ci.yml/badge.svg)

> This is a Node.js application that showcases the current time in Moscow, adhering to best practices and coding standards. It has been thoroughly tested, ensuring that the time updates seamlessly upon page refresh.

## Framework Selection

**Node.js is an excellent choice for this task for the following reasons:**

1. Efficiency and Speed:
- Node.js is known for its event-driven, non-blocking I/O architecture. This makes it highly efficient and responsive, ideal for delivering real-time updates like the current time.

2. Ecosystem:
- Node.js boasts a rich ecosystem of packages and libraries, enabling me to easily implement the required functionality without reinventing the wheel.

## Adherence to Best Practices
Code Consistency:
- I ensured that the codebase maintained a consistent style, adhering to the established best practices within the Node.js community.

## Coding Standards

> While Node.js doesn't enforce strict coding standards, there are some common conventions and best practices followed by developers when writing Node.js code.

1. Use const and let:
- In this script, const is used for variables that should not be reassigned (http, server, port), and let is used for variables (randomNumber) that may change their value.

2. Arrow Functions:
- The script uses arrow functions for defining the callback functions, such as (req, res) => {...} and () => {...}. Arrow functions are commonly used in Node.js for concise and clean syntax.
17 changes: 17 additions & 0 deletions app_node/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const http = require('http');

const server = http.createServer((req, res) => {
// Generate a random number between 1 and 21
const randomNumber = Math.floor(Math.random() * 21) + 1;

// Set the response headers
res.writeHead(200, { 'Content-Type': 'text/plain' });

// Send the random number as the response
res.end(`Random Number: ${randomNumber}\n`);
});

const port = 3000;
server.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
Loading