WeHelp
淺談從本地到 AWS 程式碼部署流程
2023-09-03 19:45:36

第一次部署至 AWS EC2,對於看不見、摸不著的東西有點難以想像,
嘗試著在腦中思考著機器間的關聯後簡單整理了概念圖和簡易說明如下:

  • 概念圖(使用 Excalidraw 繪製)
    image

一、程式碼管理與同步

編輯好程式後,可使用 git status 檢查變更的部分,
使用 commit 將這些變更記錄下來(助於版本控制),
再使用 push 指令將它們推送至 GitHub,
完成後可至 GitHub 確認是否更新成功。

二、程式碼部署至 AWS EC2

(假設已連線至 AWS EC2 伺服器)

1. 第一次從 GitHub 複製

首次部署時,使用 clone 從 GitHub 複製程式碼,以建立 EC2 上的程式碼副本。

2. 定期更新程式碼

為了保持程式碼的最新狀態,使用 pull 將 GitHub 上的最新程式碼拉回 EC2。

補充:
可使用 git log 檢查是否已取得最新的程式碼
(若被卡在 git log 畫面中,可以按 q (quit) 退出)

MySQL 資料庫管理

若程式需使用到 MySQL,則必須在本地和 AWS EC2 上管理資料庫以及資料表結構的同步,
簡單分享幾種建立資料表結構的方式:

使用 sql 檔

方法 1:使用 Secure Copy (SCP)

在 EC2 建立接收檔案用的資料夾,再從本地使用 Secure Copy (SCP) 將資料複製到 EC2

方法 2:透過 GitHub 傳輸 sql 檔

透過 GitHub 傳輸 sql 檔(如果其他人也需使用到,採用此方法可能較方便)

不使用 sql 檔

直接進到 EC2 的 MySQL 下指令


(英文版)

Exploring the Code Deployment Process from Local to AWS

Deploying to AWS EC2 for the first time can be a bit challenging when dealing with something you can't see or touch. Here is a simplified conceptual diagram and brief explanation:

  • Conceptual Diagram (Created with Excalidraw)
    image

I. Code Management and Synchronization

After editing your code, you can use git status to check for changes. To maintain version control, use commit to record these changes. Then, use the push command to send them to GitHub. You can verify the success of the update on GitHub.

II. Code Deployment to AWS EC2

(assuming you are already connected to the AWS EC2 server)

1. First-time Clone from GitHub

For the initial deployment, use the clone command to copy the code from GitHub, creating a code copy on AWS EC2.

2. Regular Code Updates

To ensure your code remains up-to-date, use the pull command to fetch the latest code from GitHub to AWS EC2.

Additional note:
You can use the git log command to check if you have obtained the latest code. If you find yourself stuck in the git log display, you can press q (quit) to exit.

MySQL Database Management

If your application requires MySQL, you need to synchronize database and table structures locally and on AWS EC2. Here are a few methods for creating table structures:

Using SQL Files

Method 1: Using Secure Copy (SCP)

Create a folder on EC2 for receiving files and then use Secure Copy (SCP) from your local machine to copy data to EC2.

Method 2: Transmitting SQL Files via GitHub

Transmit SQL files via GitHub (this method might be more convenient if others also need access).

Without SQL Files

You can directly access EC2's MySQL and execute SQL commands.

6 comments