TIL

송은우·2022년 4월 8일
0

ECR

docker hub와 유사한 기능. aws의 docker hub다 라고 생각하면 됨

ECS

Github actions

action은 다양한 곳에서 정의 가능.
1. 동일 repository
2. 모든 public repository
2. 도커 이미지 (docker hub)

중간에 url 이나 repo가 바뀌면 전꺼는 fail처리

|-- hello-world (repository)
|   |__ .github
|       └── workflows
|           └── my-first-workflow.yml
|       └── actions
|           |__ hello-world-action
|               └── action.yml
Example workflow file:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # This step checks out a copy of your repository.
      - uses: actions/checkout@v3
      # This step references the directory that contains the action.
      - uses: ./.github/actions/hello-world-action

이렇게 동일 repo에서 action 정의 가능함

다른 public repo
with the {owner}/{repo}@{ref} syntax in your workflow file.

The action must be stored in a public repository.

jobs:
  my_first_job:
    steps:
      - name: My first step
        uses: actions/setup-node@v3

도커 허브

  my_first_job:
    steps:
      - name: My first step
        uses: docker://alpine:3.8

어떤 액션을 사용할 지는 버전을 지정할 수 있다.
tag도 가능하고, SHA 코드도 가능하고, 브랜치도 가능함.

steps:
  - uses: actions/javascript-action@main

io도 지정 가능함

name: "Example"
description: "Receives file and generates output"
inputs:
  file-path: # id of input
    description: "Path to test script"
    required: true
    default: "test-file.js"
outputs:
  results-file: # id of output
    description: "Path to results file"

variable을 사용하는 것은

jobs:
  example-job:
      steps:
        - name: Connect to PostgreSQL
          run: node client.js
          env:
            POSTGRES_HOST: postgres
            POSTGRES_PORT: 5432

로 다른 ci/cd처럼 env를 통해 준다.

jobs:
  example-job:
    steps:
      - run: npm install -g bats

같은 방식으로 global install도 가능함.
run에 ~~~.sh 같은 것으로 쉘 스크립트도 작동 가능

run: build.sh
shell: bash 로 옵션은 줘야 됨

jobs:
  example-job:
    name: Save output
    steps:
      - shell: bash
        run: |
          expr 1 + 1 > output.log
      - name: Upload output file
        uses: actions/upload-artifact@v3
        with:
          name: output-log-file
          path: output.log
jobs:
  example-job:
    steps:
      - name: Download a single artifact
        uses: actions/download-artifact@v3
        with:
          name: output-log-file

이런 방식으로 데이터를 공유할 수 있는데, job들 사이에서 파일을 읽고 쓰는 방식으로 처리할 수 있다.
아티팩트는

expression 은 ${{ expression}} 같이 넣어야 제대로 작동함.

string으로 취급하지 않고, env같은 경우 그냥 null이나 숫자 값을 넣고 싶으면

env:
  myNull: ${{ null }}
  myBoolean: ${{ false }}
  myIntegerNumber: ${{ 711 }}
  myFloatNumber: ${{ -9.2 }}
  myHexNumber: ${{ 0xff }}
  myExponentialNumber: ${{ -2.99-e2 }}
  myString: Mona the Octocat
  myStringInBraces: ${{ 'It''s open source!' }}

같은 방법으로 가능함
다른 연산자
근데 추가적으로 각종 함수들도 있음
결과값을 가지고
contains(search,item)
startsWith( searchString, searchValue )
endsWith( searchString, searchValue )
format( string, replaceValue0, replaceValue1, ..., replaceValueN)
format('{{Hello {0} {1} {2}!}}', 'Mona', 'the', 'Octocat')
join( array, optionalSeparator )
toJSON(value)
같은 방식을 사용해서
이렇게 예제를 검사나 변환할 수 있음

name: build
on: push
jobs:
  job1:
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - id: set-matrix
        run: echo "::set-output name=matrix::{\"include\":[{\"project\":\"foo\",\"config\":\"Debug\"},{\"project\":\"bar\",\"config\":\"Release\"}]}"
  job2:
    needs: job1
    runs-on: ubuntu-latest
    strategy:
      matrix: ${{fromJSON(needs.job1.outputs.matrix)}}
    steps:
      - run: build

json형식으로 나온 결과를 바꾸는 코드

name: print
on: push
env: 
  continue: true
  time: 3
jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
      - continue-on-error: ${{ fromJSON(env.continue) }}
        timeout-minutes: ${{ fromJSON(env.time) }}
        run: echo ...

역방향 json 을 결과로
if: ${{ success() }}
부분은 앞 부분이 전부 다 성공했을 경우에 이렇게 표현 조건에 따라서 if 를 처리할 수 있음
if: ${{ always() }}
if: ${{ failure() }}
이 코드로 github actions를 세팅할 수 있음
if: ${{ job.status == 'failure' }}
같은 비교도 가능함
{
"scallions":
{
"colors": ["green", "white", "red"],
"ediblePortions": ["roots", "stalks"],
},
"beets":
{
"colors": ["purple", "red", "gold", "white", "pink"],
"ediblePortions": ["roots", "stems", "leaves"],
},
"artichokes":
{
"colors": ["green", "purple", "red", "black"],
"ediblePortions": ["hearts", "stems", "leaves"],
},
}
이 객체가 만약 vegetables 라면,
vegetables.*.ediblePortions
이 코드로
[
["roots", "stalks"],
["hearts", "stems", "leaves"],
["roots", "stems", "leaves"],
]
이게 가능함

컨텍스트

컨텍스트
컨텍스트는 다양한 작업 단계, 환경, 실행같은 것들에 접근할 수 있는 객체
${{<context>}}
github라는 컨텍스트 종류에 접근하는 2방법
1. github['sha']
2. github.sha

etc)
gitflow 실제로 적용하는 방법

profile
학생의 마음가짐으로 최선을 다하자

0개의 댓글