kiese
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Secure System Development Lab 1 **Team Members:** * Daniyar Cherekbashev (d.cherekbashev@innopolis.university) * Gleb Statkevich (g.statkevich@innopolis.university) * Daria Kalashnikova (d.kalashnikova@innopolis.university) ## Part I - Continuous Integration ### Task 1 **1. Q: What is the pipeline method of software development?** A: The pipeline method is a software development strategy that divides the process into units - stages (build, test, deploy). They are responsible for specific aspects, and each stage takes place sequentially. **2. Q: What tasks and problems does the CI/CD process solve?** A: CI - Continuos Integration (mainly building and testing software artifacts), CD - Continuos Deployment (stage, at that we deploy artifacts/image to environment). The CI/CD process automates projects's code management tasks. It allows to: integrate code updates into a shared repository regularly, automatically test ensure quality (tests, security, etc.), quickly and efficiently deploy applications to production. CI/CD process minimizes manual human-factor errors, enhances teamwork, and speeds up software updates. **3. Q: What kind of general stages are there in the CI/CD pipeline? List them in the correct sequence and then describe them.** A: Building - build software artifacts and then scan for vulnerabilities, Testing - test newly created artifacts. After that we can push artifacts to some artifacts repo (Nexus, Artifactory, e.g.), Deploying - deploy artifacts to environment. **4. Q: Describe the difference(s) between unit testing and coverage testing.** A: Unit testing - test one or more software modules and focuses on individual components of code in isolation to ensure they work as expected. Often, this is a first stage of testing job in pipeline. Coverage testing usually measures proportion of source code being tested via autotests. While unit testing focuses on the correctness of individual units of code, coverage testing measures the effectiveness of the tests in covering the codebase. **5. Q: What are Job Artifacts and Artifacts Storage?** A: Job Artifacts - built software in pipeline workspace, a result of the CI/CD stages (compiled code, test reports, or deployment packages). Artifacts Storage - a repository that store built artifacts for future reference/use (for troubleshooting, auditing, or rollback purposes.), also used for caching build dependencies and others. ### Task 2 1. Created user for our team: ![users](https://hackmd.io/_uploads/B1yLV0Sk0.png) 2. Application: <span style="color: green">main.py</span> ```python= from flask import Flask import datetime import pytz app = Flask(__name__) @app.route('/') def display_time() -> str: # Retrieving Innopolis (Moscow) timezone info timezone: datetime.tzinfo = pytz.timezone('Europe/Moscow') inno_time: str = datetime.datetime.now(timezone).strftime("%d %B, %H:%M:%S") return f'Hello Human! Time is: {inno_time}' if __name__ == '__main__': app.run() ``` <span style="color: green">requirements.txt</span> ``` pytz~=2022.7 flask~=2.2.2 ``` Pushed changes to remote repo after adding public ssh key to the team user: ![gitlab-rep](https://hackmd.io/_uploads/S1DdN0B1R.png) 3. Deploying a Gitlab Runner: Internal gitlab host was retrieved with `ip r` command. ![runner-terminal](https://hackmd.io/_uploads/Bybm7kUJ0.png) After deploying: ![runner](https://hackmd.io/_uploads/SyFHGJ81C.png) Docker compose file of the previous steps: <span style="color: green">docker-compose.yml</span> ```yaml= version: '3.5' services: gitlab: image: gitlab/gitlab-ee:latest hostname: ssd.inno.local restart: always environment: GITLAB_OMNIBUS_CONFIG: | gitlab_rails['gitlab_shell_ssh_port'] = 8022 external_url 'http://ssd.inno.local' ports: - "8022:22" - "8080:80" - "8443:443" volumes: - ./config/gitlab:/etc/gitlab - ./data/gitlab:/var/opt/gitlab - ./logs:/var/log/gitlab networks: gitlab: aliases: - 'ssd.inno.local' gitlab-runner: image: gitlab/gitlab-runner:alpine restart: unless-stopped depends_on: - gitlab volumes: - ./config/gitlab-runner:/etc/gitlab-runner - /var/run/docker.sock:/var/run/docker.sock networks: - gitlab networks: gitlab: driver: 'bridge' ``` ## Part II - Continuous Deployment ### Task 3 <span style="color: green">Dockerfile</span> ```dockerfile FROM docker.io/library/python:3.9.2 as build COPY requirements.txt / WORKDIR /app RUN adduser --disabled-password puppet && chown -R puppet /app COPY main.py ./ COPY requirements.txt ./ USER puppet RUN python -m pip install -r /requirements.txt EXPOSE 5000 CMD ["python", "main.py"] ``` Best practices used: * The use of stable base image: Precise version python:3.9.2 is used to ensure consistency and avoid potential compatibility issues between different versions. * Keeping layers immutable: Files or dependencies are not changed in the middle of the Dockerfile, as it can lead to inconsistencies and security vulnerabilities. * Run as a non-root user: Application is run as a non-root user to minimize the potential security risks. ### Task 4 <span style="color: green">.gitlab-ci.yml</span> ```yaml= stages: - build - deploy default: image: docker:24.0.5 services: - docker:24.0.5-dind before_script: - docker info variables: DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" build-job: stage: build tags: - docker script: - docker build -t $DOCKERHUB_IMAGE -f Dockerfile . - docker login -u $DOCKERHUB_USER -p $DOCKERHUB_TOKEN docker.io - docker tag $DOCKERHUB_IMAGE:latest $DOCKERHUB_USER/$DOCKERHUB_IMAGE:latest - docker push $DOCKERHUB_USER/$DOCKERHUB_IMAGE:latest deploy-job: image: ubuntu:latest stage: deploy tags: - default only: - master before_script: - apt-get -yq update - apt-get -yqq install ssh - install -m 600 -D /dev/null ~/.ssh/id_rsa - echo "$SSH_PRIVATE_KEY" | base64 -d > ~/.ssh/id_rsa - ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts script: - ssh $SSH_USER@$SSH_HOST "docker run -d -p 5000:5000 $DOCKERHUB_USER/$DOCKERHUB_IMAGE:latest" ``` To make runner work and correctly resolve hosts, we should add `network_mode = "srv_gitlab"` (network name can be found with `docker network ls`) to the `/etc/gitlab-runner/config.toml` of our runner in `gitlab-runner` container. We should also add `privileged = true` to correctly run docker-in-docker container. ```toml [[runners]] ... [runners.docker] privileged = true ... network_mode = "srv_gitlab" ``` Also, we should create CI/CD variables for our CI file: ![image](https://hackmd.io/_uploads/Hyji_Fd1C.png) Passed jobs: ![image](https://hackmd.io/_uploads/rkC4KKO1R.png) ![image](https://hackmd.io/_uploads/r13_KKu1A.png) ![image](https://hackmd.io/_uploads/rkghKKuyC.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully