참고

기본 문법 정리

병렬처리

jobs:
  build-docker:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        platform:
          - linux/amd64
          - linux/arm/v7
          - linux/arm64/v8
 
===이렇게 변수로 참조===
${{ matrix.platform }}
  • 이렇게 수행하면 platform 내부 변수들을 통해 github actions 가 각각 Runner를 할당 받아서 빌드한다

SPA 배포시

  1. 404.html 다운로드 후 index.html과 같은 폴더에
  2. 메인 index.html head 테그에 해당 구문 추가
<script type="text/javascript">
	// Single Page Apps for GitHub Pages
	// MIT License
	// https://github.com/rafgraph/spa-github-pages
	// This script checks to see if a redirect is present in the query string,
	// converts it back into the correct url and adds it to the
	// browser's history using window.history.replaceState(...),
	// which won't cause the browser to attempt to load the new url.
	// When the single page app is loaded further down in this file,
	// the correct url will be waiting in the browser's history for
	// the single page app to route accordingly.
	(function (l) {
		if (l.search[1] === "/") {
			var decoded = l.search
				.slice(1)
				.split("&")
				.map(function (s) {
					return s.replace(/~and~/g, "&");
				})
				.join("?");
			window.history.replaceState(null, null, l.pathname.slice(0, -1) + decoded + l.hash);
		}
	})(window.location);
</script>
  1. 추가설정
    • react-router 사용시
      createBrowserRouter([...각종라우팅], {basename: process.env.PUBLIC_URL})
    • 이외에 url을 /a/b 이런식으로 따로 참조하고 있는경우 앞에 process.env.PUBLIC_URL/a/b
    • html은 %PUBLIC_URL% 로
    • package.json에 해당 구문 추가
      "homepage": "[원본 도메인주소]",
    • 따로 커스텀 도메인을 설정했다면 404.htmlpathSegmentsToKeep 값을 0로 설정 (디폴트)

릴리스 생성시 작동하는 job

해당하는 job 에 해당 구문 추가
 - `if: startsWith(github.ref, ‘refs/tags/’)“

릴리스 생성시 결과물 릴리스에 배포법

  • action-gh-release 사용

Github Actions 릴리스(태그) 생성시에만 작동시키기

on:
    push:
		tags:
			- "**"

Github Page에 커스텀도메인 적용

  1. dig [원래 페이지 도메인] +noall +answer -t A
  2. 거기서 나온 ip 전부를 dns에 등록
  3. Github Page 사이트에서 Custom domain에 등록한 domain 입력

적용에는 1시간 이상 걸릴 수 있음

Github Runner

  • 원래Actions 자체에서 VM 을 할당하는데 이를 내 자체 서버를 사용 할수있음
  • 이를 통해 커밋 이후에 내 서버에 뭔 갈 하거나 이런게 가능해짐

    Runner를 사용하지 않다면 actions에서 ssh 연결을 통해 조작할 수도 있음

GitHub 조직 Dcoker 컨테이너 패키지 배포

참고자료

조직 토큰 설정하기

개인 토큰 발행

범위설명필요한 권한
read:packagesGitHub Packages에서 패키지 다운로드 및 설치읽기
write:packagesGitHub Packages에 패키지 업로드 및 게시쓰기
delete:packagesGitHub Packages에서 패키지 삭제관리자
repo패키지 업로드 및 삭제(write:packages 또는 delete:packages 포함)쓰기 또는 관리자

해당 개인 토큰으로 Docker에 로그인 하고 push 하기

echo <개인토> | docker login ghcr.io -u Lseoksee --password-stdin
docker buildx build --push -t ghcr.io/<조직>/<이미지> .

기타

  • 보니까 Github ghcr.io 라는 Docker Hub 와 같은 이미지 공유 사이트를 운영하는듯
  • 개인 리포지토리나 조직에 이미지를 ghcr.io로 Push 하는 구조를 가짐

GitHub Actions 사용 예제

참고자료

  • 단일 플렛폼
    name: Publish Docker image
     
    on:
      push:
        branches: 
            - main
      workflow_dispatch:
     
    jobs:
      # fitpin-ar-backend 빌드
      publish_fitpin-ar-backend:
        runs-on: ubuntu-latest
        env:
          PLAT_FORM: linux/amd64,linux/arm64
          IMAGE_NAME: fitpin-ar-backend
          FILE_LOCATION: ./AR-BackEnd/
        permissions:
          contents: read
          packages: write
          attestations: write
          id-token: write
     
        steps:
          - name: Checkout repository
            uses: actions/checkout@v4.2.1
     
          - name: Log in to the Container registry
            uses: docker/login-action@v3.3.0
            with:
              registry: ghcr.io
              username: ${{ github.actor }}
              password: ${{ secrets.ACTIONS_TOKEN  }}
     
          - name: Docker Setup Buildx
            uses: docker/setup-buildx-action@v3.7.1
            with:
              driver: docker-container
              driver-opts: |
                image=moby/buildkit:master
              platforms: ${{ env.PLAT_FORM }}
            
          - name: Build and push ${{env.IMAGE_NAME}} Docker image
            id: push
            uses: docker/build-push-action@v6.9.0
            with:
              platforms: ${{ env.PLAT_FORM }}
              context: ${{ env.FILE_LOCATION }}
              push: true
              tags: ghcr.io/fit-pin/${{ env.IMAGE_NAME }}:latest
              cache-from: type=registry,ref=ghcr.io/fit-pin/${{ env.IMAGE_NAME }}:latest
              cache-to: type=inline
     
          - name: Generate artifact attestation
            uses: actions/attest-build-provenance@v1
            with:
              subject-name: ghcr.io/fit-pin/${{ env.IMAGE_NAME}}
              subject-digest: ${{ steps.push.outputs.digest }}
              push-to-registry: true
  • 멀티 플렛폼 + 병렬처리
    기본 제공 Runner의 용량 문제로 병렬로 할당 받아 쓰는것이 유리함