Sean Wei
    • 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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- type: slide tags: presentation title: 自動化部署 - 資訊之芽 2023 Python 語法班 description: Sean 韋詠祥 / 2023-07-02 --- # 自動化部署 資訊之芽 2023 Python 語法班 Author: Sean 韋詠祥 Note: 14:00 發密碼、安裝 SSH client 14:05 開始講課、部署理由 14:10 Linux 指令介紹 14:20 介紹 Git 14:25 VS Code Git 操作 14:30 註冊 GitHub 帳號 14:35 建立 Repo、add remote 14:40 遠端 clone、安裝環境 14:50 介紹 CI/CD 14:55 安裝 GitHub Actions 15:05 嘗試觸發部署 15:15 指令列 Git 操作 (緩衝用) 15:25 下課 ---- ## 課前準備 - 用 VS Code 開啟 Discord Bot 專案 - 在自己的筆電安裝 SSH 用戶端 - 拿到密碼紙,連上遠端伺服器 ---- ## 為何安排這堂課 未來展望? ---- ## 現況回顧 - 寫完 Discord Bot 了 - 在筆電上運行 - 收起電腦之後呢? - 修改記錄不易追蹤 ---- ## 今天目標 - 暸解版本控制概念、用法 - 學會「部署」到遠端伺服器 - 建立自動化流程 ---- ## 課堂綱要 - 前言 - Linux 指令教學 - Git / GitHub 簡介 - CI/CD 自動化部署 - 補充:指令列 Git 操作 --- # Linux 指令教學 基本 Bash 指令 ---- ## Part 1 ```bash cd example # 進入資料夾 cd .. # 回到前一層目錄 cd # 不加參數,代表回到家目錄 ``` ```bash pwd # 顯示當前目錄 ``` <br> ```bash ls # 列出目前目錄下的檔案 ls -l # 顯示詳細資訊 ls -a # 包含隱藏檔案 ls -al # 我全都要! ``` ---- ## Part 2 ```bash cat slides.md # 印出檔案內容 ``` ```bash less /etc/passwd # 慢慢查看檔案內容 ``` <br> ```bash echo Hello echo Hello World echo Hello World echo "Hello World" ``` <br> ```bash echo "Hey there" > myfile echo "Hey there" >> myfile ``` ---- ## Part 3 ```bash touch myfile # 建立空檔案 ``` ```bash mkdir mycode # 建立資料夾 ``` <br> ```bash mv myfile file1 # 移動檔案 ``` ```bash cp file1 file2 # 複製檔案 ``` <br> ```bash rm file1 # 刪除檔案 ``` ```bash rmdir mycode # 刪除空資料夾 ``` --- # 版本控制簡介 Git 核心邏輯 ---- ## 你有沒有看過... ![課程簡報 複製 最終版 完稿](https://i.imgur.com/uZArLj9.png) ---- ## 什麼是版本控制? ![git lg graph](https://i.imgur.com/HqNNopD.png) ---- ## 傳統中央控管型 ![Central VCS Server -> Computer A B](https://i.imgur.com/cT78gbx.png) ---- ## 分散式版本控制系統 ![Version Database](https://i.imgur.com/OkbeF6I.png) ---- ## Git 核心使用概念 ![Working Staging .git](https://i.imgur.com/x5r0Y34.png) ---- ## VS Code 實際操作 使用 Git 擴充套件 --- # 註冊 GitHub 帳號 ![GitHub Homepage](https://hackmd.io/_uploads/B1haGdA_2.png) 網站:https://github.com/ ---- ## 填寫帳號資料 ![CAPTCHA](https://hackmd.io/_uploads/SyYn7_A_h.png) 驗證碼:選出相同物品 ---- ## 收驗證信 ![confirm code](https://hackmd.io/_uploads/SyvGE_ROn.png) ---- ## 個人分析資料 ![Welcome](https://i.imgur.com/cTHU9Se.png) 可點擊下方 Skip 跳過 ---- ## 建立 Repo ![](https://hackmd.io/_uploads/SyK1HuRO2.png) ---- ## 上傳程式碼 - 透過 VS Code 連結 GitHub 帳號 - 選擇對應 Repo - 上傳(Push)程式碼 --- # 設定遠端伺服器 抓取程式碼、安裝環境 ---- ## 抓取程式碼 使用 git clone 指令 ```bash git clone https://github.com/Sean-Py2023/dc-bot.git cd dc-bot ls ``` ---- ## 安裝環境 已安裝 python3.11 及 pip 程式 請自行安裝需要的 pip 套件 ```bash pip install discord pip install python-dotenv pip install .... ``` ---- ## 執行 Discord Bot 跟筆電上方式類似 ```bash python3 bot.py ``` <br> 記得把 `.env` 也帶過去 ```bash nano .env # 編輯檔案 ``` --- ## CI/CD 自動化部署 Continuous Integration Continuous Delivery Continuous Deployment ---- ## Continuous Integration 持續整合 - Build 程式建置 - Unit Test 單元測試 - Integration Test 整合測試 - Merge 合併至主幹 ---- ## Continuous Delivery 持續交付 - 編譯、產生執行檔 - 產生 Docker 映像檔 ---- ## Continuous Deployment 持續部署 - Dev -> Staging -> Production - 自動監控系統健康度 --- # GitHub Actions 由 GitHub 提供的 CI/CD 服務 ---- ## 設定 SSH 金鑰 ssh-keygen -t ed25519 cat .ssh/id_ed25519.pub >> .ssh/authorized_keys ---- ## 設定 GitHub Actions ![](https://hackmd.io/_uploads/ByTYMqC_3.png) 設定檔:[GitHub Gist](https://gist.github.com/Sea-n/5c324c52ea9f9ef4798631036731f57e) ---- ## 嘗試觸發部署 --- # 指令列 Git 操作 補充教材 ---- ## 建立本地 Repo Git Repository ```bash cd ~ mkdir my-project # 建立資料夾 cd my-project git init # 初始化 git ``` ```bash touch main.py # 建立 main.py 或 main.cpp 檔案 git add main.py # 把檔案從 working area 加入 staging area ``` ```bash git commit # 在編輯器中輸入 commit 訊息:init ``` ```bash # 完成! ``` ---- ## 稍微改點東西 先用編輯器打開 `main.py` 檔案 ```bash nano main.py ``` 用 `for` 跟 `range()` 讓他輸出 0 到 4 這五個數字,每次換行 完成後用 git 保存版本紀錄 ```bash git status # 有誰被改到了 git add main.py git commit ``` Note: 先講 status 下頁講 diff 再來是 show ---- ## 需求變更 輸入:一個正整數 N 輸出:從 0 到 N-1 的數字,每次換行 ```bash git diff # 我們改了什麼 git add -p main.py git commit ``` Hint:用 `int(input())` 接收輸入 Note: 剛講 status 現在是 diff 下頁講 show ---- ## 再次修改 輸入:一個正整數 N 輸出:從 1 到 N 的數字,每次換行 ```bash git add -p . git commit -m '<commit message>' ``` 試著查看歷史紀錄 ```bash git show # 預設為 HEAD git show HEAD~1 # 往前 1 筆 ``` Note: 講完 status、diff 這頁講 show ---- ## 歷史回顧 試試這個指令吧 ```bash git log ``` <br> 幫大家設定好更漂亮的版本了: ```bash git lg ``` --- # Thanks 投影片連結:https://hackmd.io/@Sean64/cicd-sprout2023 <!-- .element: class="r-fit-text" --> <br> [![CC-BY](https://mirrors.creativecommons.org/presskit/buttons/88x31/png/by.png)](https://creativecommons.org/licenses/by/4.0/deed.zh_TW) ###### 這份投影片以 [創用 CC - 姓名標示](https://creativecommons.org/licenses/by/4.0/deed.zh_TW) 授權公眾使用,原始碼及講稿請見 [此連結](https://hackmd.io/@Sean64/cicd-sprout2023/edit)。 <style> .reveal pre.wrap-code code { white-space: pre-wrap; } </style>

    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