Compute Engine with Github in GCP

Page content

개요

Untitled

터미널 열기

  • 기존 인스턴스는 중지를 시켰기 때문에 이를 다시 시작/재개 버튼을 눌러 활성화 한다.

Untitled

  • 시작 버튼 클릭과 함께 오늘도 비용을 지불해본다.

Untitled

  • 브라우저 창에서 열기를 진행한다.

Untitled

Git 설치

  • 터미널에 Git을 설치하는 방법은 다음 명령어를 순차적으로 입력한다.
(base) ~$ sudo apt-get update -y
(base) ~$ sudo apt-get upgrade -y
(base) ~$ sudo apt install git
(base) ~$ git --version

Git Repo 생성

  • Github에서 Repo를 만든다. (Repo : mulcampFP)
    • 보안을 위해 Private으로 지정한다.

Untitled

SSH Key값 설정

  • 본인의 깃허브 이메일을 추가하여 아래와 같이 코드를 실행한다.
(base) ~$ ssh-keygen -t rsa -b 4096 -C “your@email.com”

Untitled

  • 키값을 복사하기 위해 다음 명령어를 실행한다.
(base) ~$ cat .ssh/id_rsa.pub

Untitled

  • Github > MyProfile > Settings 클릭한다.

Untitled

  • SSH and GPG Keys를 클릭한다.

Untitled

  • New SSH Key 버튼을 클릭한다.

Untitled

  • 아래와 같이 복사한 후 저장을 누른다.

Untitled

  • 인증을 하여 마무리를 한다.

Untitled

메타 데이터 등록

  • 왼쪽 사이드바 메뉴에서 Compute engine > 설정 > 메타데이터 항목에서 SSH키에 추가를 한다.

Untitled

  • 아래와 같이 키를 등록해준다.

Untitled

Github Repo 연동

  • 경로를 복사한다. (SSH 탭 클릭 후 주소 복사)

Untitled

  • 현재 필자의 경로는 아래와 같다. 이전 글에서 작업한 파일이 있는 것을 확인한다.
(base) ~$ pwd
/home/your_id
(base) ~$ ls
Untitled.ipynb  miniconda3
  • 복사한 경로를 아래와 같이 붙여 넣는다.
(base) ~$ git clone git@github.com:dschloe/mulcampFP.git
Cloning into 'mulcampFP'...
The authenticity of host 'github.com (20.200.245.247)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,20.200.245.247' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.
(base) ~$ ls
Untitled.ipynb  miniconda3  mulcampFP

Untitled

Github 간단 테스트

  • vi 편집기로 README.md 파일을 열어서 간단하게 글자 몇개를 추가하고 저장한다.
# mulcampFP

- success from GCP
  • 먼저 로그인을 진행한다. (경로 이동 과정은 생략했다. 여러분들의 깃허브 폴더로 이동한다.)
(base) ~/mulcampFP$ git config --global user.email "your_id@email.com"
(base) ~/mulcampFP$ git config --global user.name "yourname"
  • 업데이트를 한다.
(base) ~/mulcampFP$ git add .
(base) ~/mulcampFP$ git commit -m "updated"
[main 3271b58] updated
 1 file changed, 3 insertions(+), 1 deletion(-)
(base) ~/mulcampFP$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 302 bytes | 302.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:dschloe/mulcampFP.git
   bb07067..3271b58  main -> main
  • 정상적으로 반영이 된 것을 확인할 수 있다.

Untitled

  • 이번에는 깃허브에서 임시 파일을 하나 만들고 간단하게 파일을 생성한다.

Untitled

  • 이번에는 git pull 명령어를 실행하여 정상적으로 파일이 다운로드 되는지 확인한다.
(base) ~/mulcampFP$ git pull
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 717 bytes | 717.00 KiB/s, done.
From github.com:dschloe/mulcampFP
   3271b58..daa4600  main       -> origin/main
Updating 3271b58..daa4600
Fast-forward
 main.py | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 main.py
(base) ~/mulcampFP$ ls
README.md  main.py
(base) ~/mulcampFP$ python main.py 
Traceback (most recent call last):
  File "/home/j2hoon85/mulcampFP/main.py", line 1, in <module>
    import pandas as pd 
    ^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'pandas'
  • 아직 라이브러리를 설치하지 않았다. 이제 본격적으로 필수 라이브러리를 설치하고 간단하게 테스트를 진행해본다. (다음 글에서 작성)

마무리 (인스턴스 중지 및 비용)

  • 인스턴스 중지를 꼭 한 후, 비용 체크를 진행한다.

Untitled

(추가) Github Password

  • 간혹 터미널에서 Github Password를 입력하라고 하면 Settings > Developer Settings > Tokens (classic) 에서 토큰을 발행하면 된다.

Untitled