Git

Crontab으로 Git Commit Automation with sh 파일 on M1

개요

  • Mac Crontab으로 SH 파일을 실행하도록 한다.

SH 파일 작성

  • 주요 내용은 아래와 같이 작성한다. (파일명 : deploy.sh)
#!/bin/bash
echo "Git Push Starting..."

cd /Users/evan/Desktop/alphaco_test

# Check out repo
git add -A
git commit -m "Automated commit on $(date '+%Y-%m-%d %H:%M:%S')"
git push                                                             

수동 업로드

  • 수동으로 업로드 하기 위해 파일 권한을 열어준다.
    • 777은 소유자, 그룹, 다른 모든 사용자에게 읽기, 쓰기, 실행 권한 부여하는 명령어를 말한다.
chmod 777 deploy.sh

실행

  • 해당 파일이 있는 경로에서 deploy.sh 파일을 실행한다.
~$ ./deploy.sh 

Crontab 등록

Screenshot 2024-09-28 at 4.05.42 PM.png

Github Actions with GCE, SSH-Key 값 등록

개요

  • Github Actions 강의 중, 애매한 부분을 정리하였다.
  • Github Actions에 대한 전체 코드는 여기에서 다루지는 않는다.

SSH-Key 값 설정

  • GCE에서 Github와 연동을 위해서는 Key값을 생성해야 한다.
  • 본인의 구글클라우드 이메일을 추가하여 아래와 같이 코드를 실행한다.
  • GCP의 ID와 Github의 이메일 주소가 다른 분들이 있다. 이럴 경우 문제가 발생할 수 있다.
    • 주의 : Github 이메일 주소가 아님
$ ssh-keygen -t rsa -b 4096 -C "your@gmail.com"

Github SSH Key값 생성

  • ssh의 public 키값을 복사한다.
$ cat .ssh/id_rsa.pub 
ssh-rsa AAAAB3...Q== your@gmail.com

Github SSH 등록

  • public key값을 복사하여 아래 SSH and GPG keys 값에 복사한다.

Untitled

Github Actions Hello World From Python Script

개요

  • Python Script를 활용하여 Hell World를 출력한다.

강의소개

이전 게시글

main.py 작성

  • 간단하게 아래 코드를 작성한다.
  • 코드 작성은 Github에서도 가능하다.
import sys

print(sys.version)
print("Hello, World")
  • Add file > Create new file 버튼을 클릭한다.

Untitled

Github Actions Hello World

개요

  • Github Actions 에서 Hello World를 출력하도록 한다.

강의소개

사전준비

  • Github에 적당한 Repo를 준비한다.

메뉴선택

  • 아래 그림에서 Actions 메뉴를 선택한다.

Untitled

  • 아래 그림에서 set up a workflow yourself 선택

Untitled

YAML 파일 수정

  • .github/workflows/main.yaml 파일 선택 후 수정

Untitled

BigQuery Connect to Google Analytics

개요

  • BigQuery에서 Google Adwords 데이터와 Google Analytics를 불러올 수 있다.

전제조건

  • 구글 클라우드 사용법은 어느정도 알고 있는 상태를 전제로 한다.
  • Google Analytics를 이미 활용하고 있다는 것을 전제로 한다.

Google Analytics

  • 왼쪽 메뉴에서 관리 > 제품 링크를 확인한다.

Untitled

Untitled

  • BigQuery 링크 클릭 > 연결 버튼을 클릭한다.

Untitled

  • BigQuery 프로젝트를 선택한다.

Untitled

  • 활성화중인 프로젝트를 선택한다.

Untitled

  • 데이터 위치를 지정한다. 본 프로젝트에서는 서울로 명명한다.

Untitled

  • 내보내기 유형은 매일로 선택한다.

Untitled

  • 사용자 데이터는 일별로 선택한다.

Untitled

Streamlit App Deployment Compute Engine with Github Action in GCP

개요

  • Google Compute Engine에서 Gihub Action을 구현하도록 한다.

프로젝트 생성

  • 새 프로젝트 버튼을 클릭 후 프로젝트 명을 streamlit-gitaction으로 명명한다.

Untitled

Instance 생성

  • Compute Engine > VM Instance 선택 후, 새로운 인스턴스를 생성한다.

Untitled

  • 처음 사용하는 경우 사용 버튼을 클릭한다.

Untitled

  • 최초 작업에는 결제 필요 버튼이 나올 수 있다. 결제 사용 설정을 눌러 결제를 추가한다.

Untitled

Untitled

  • 필자는 회사 계정을 사용한 것이므로 이렇게 나오지만, 일반 사용자는 화면이 다를 수 있다.
  • VM 인스턴스를 생성한다.

Untitled

Compute Engine with Github in GCP

개요

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

Git 배치파일 Windows

개요

배치파일 생성하기

  • 프로젝트 폴더에 배치파일을 실행한다.
  • 파일명은 submit.bat 로 지정했다.
set root=C:\Users\human\Desktop\streamlit-predictions
call git add .
call git commit -m "updated from batch file"
call git push

배치파일 실행하기

  • 우선 해당 폴더에서 submit.bat 파일을 더블클릭한다.

Untitled

  • 더블 클릭하면 자동으로 배치파일이 실행되면서 해당 명령어들이 순차적으로 돌아가는 것을 확인할 수 있다.

Untitled

SQL Developer with Git

개요

  • SQL Developer에서 깃헙과 연동하는 방법을 알려준다.
  • 깃허브 회원가입 및 깃 설치는 이미 된 것으로 가정한다.
  • 새로운 Repository를 만든다.
    • 필자는 oracle_lectures라는 Repository를 만들었다.

SQL Developer에서 필요한 작업

  • 이제 SQL Developer 프로그램을 연다.
    • 팀 - Git - 복제 순으로 순차적으로 연다.

Untitled

  • 아래 화면에서 다음을 클릭한다.

Untitled

  • 아래 화면에서 새로 생성한 URL, Username, Password를 순차적으로 입력한다.
    • 이 때, Repo 생성 시, Private으로 되어 있었다면 인증 에러가 생길 수 있다. 그런 경우 Public으로 변경한다.

Untitled

Hugo 깃허브 블로그 - Windows (2022)

패키지 관리자 설치

Untitled

Chocolatey (Windows)

  • If you are on a Windows machine and use Chocolatey for package management, you can install Hugo with the following one-liner:
  • 우선 PowerShell을 관리자로 실행 후, 아래와 같이 Chocolately를 설치한다.
    • 명령어 : Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('[https://community.chocolatey.org/install.ps1](https://community.chocolatey.org/install.ps1)'))
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
                                                                                                                        
새로운 크로스 플랫폼 PowerShell 사용 https://aka.ms/pscore6                                                                                                                                                                                     
PS C:\WINDOWS\system32> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)
Getting latest version of the Chocolatey package for download.
Not using proxy.
Getting Chocolatey from https://community.chocolatey.org/api/v2/package/chocolatey/1.1.0.
Downloading https://community.chocolatey.org/api/v2/package/chocolatey/1.1.0 to C:\Users\512-24\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip
Not using proxy.
Extracting C:\Users\512-24\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip to C:\Users\512-24\AppData\Local\Temp\chocolatey\chocoInstall
Installing Chocolatey on the local machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
  Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
  before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
  (i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
  and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.

Creating Chocolatey folders if they do not already exist.

WARNING: You can safely ignore errors related to missing log files when
  upgrading from a version of Chocolatey less than 0.9.9.
  'Batch file could not be found' is also safe to ignore.
  'The system cannot find the file specified' - also safe.
chocolatey.nupkg file not installed in lib.
 Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
경고: Not setting tab completion: Profile file does not exist at
'C:\Users\512-24\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'.
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
 first prior to using choco.
Ensuring Chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder
PS C:\WINDOWS\system32>

choco를 활용한 Hugo 설치

  • 설치 시, 관리자로 PowerShell을 실행한다.
$ choco install hugo-extended -confirm
  • hugo version을 확인한다.
$ hugo version
hugo v0.97.0-c07f3626e7c8160943591f4d209977efa02c3dca windows/amd64 BuildDate=2022-04-14T08:45:07Z VendorInfo=gohugoio
PS C:\WINDOWS\system32>

Git & Github 설치

Hugo 명령어를 활용한 첫번째 싸이트 만들기

  • 간단한 명령어를 활용하여 싸이트를 생성한다.
    • 명령어 : hugo new site your_blog_name
  • 필자는 폴더명을 myblog로 지정했다.
PS C:\Users\your_name\Desktop> hugo new site myblog
Congratulations! Your new Hugo site is created in C:\Users\512-24\Desktop\myblog.

Just a few more steps and you're ready to go:

1. Download a theme into the same-named folder.
   Choose a theme from https://themes.gohugo.io/ or
   create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
   with "hugo new <SECTIONNAME>\<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".

Visit https://gohugo.io/ for quickstart guide and full documentation.

Github & Submodule 설정

  • 우선 Github 세팅을 먼저 할 것이다.

깃허브 Repo 작성

  • myblog & username.github.io 두 개의 repo를 작성한다.
  • 깃허브와 현재 작성중인 폴더(myblog)를 연결한다.
    • 모든 명령어는 myblog/ 에서 적용한다.
    • 이 때 public 폴더가 있으면 지워준다.
cd myblog
rm -rf public
echo "# myblog" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/rain0430/myblog.git
git push -u origin main
  • 처음 깃헙을 하시는 분들은 주로 하단에서 에러가 나타날 것이다.
    • 이는 로그인을 하라는 뜻이다. (RUN 아래 코드를 순차적으로 실행)
$ git commit -m "first commit"
Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"
  • git commit 부터 다시 순차적으로 실행한다. git push 할 때, sign in 팝업창이 뜰 수도 있다.
  • 이제 서브모듈(Submodule)을 통해서 배포를 진행하려고 한다.
  • git 서브모듈을 추가한다.
    • 이 때, .gitmodules가 뜨는지 확인한다.
    • 또한 rain0430.github.io Repo는 새로 만들어준다.
    • 그리고 다음 명령어을 추가한다.
$ git submodule add -b main https://github.com/rain0430/rain0430.github.io.git public
  • 만약 에러가 난다면, 강제로 실행을 한다.
$ git submodule add -f https://github.com/rain0430/rain0430.github.io.git public

Hugo 기본 싸이트 확인

  • 우선 기본 테마를 설정해본다.
  • 필자는 다음 테마를 설정할 것이다. Codex | Hugo Themes (gohugo.io)
    • 테마 설정 시, 약간의 팁을 드리면, Updated가 최근 날짜인지 확인한다. 최근 날짜가 아니라면 관리가 잘 안되어 테마일수도 있다.
    • 각 테마마다 구체적인 설정 방법이 있기 때문에 각 설치 문서를 참조한다.

Untitled