Workflow
Event
Jobs
Actions
name: learn-github-actions
on: [push]
jobs:
check-bats-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: npm install -g bats
- run: bats -v
name
on
jobs
Steps
uses: actions/checkout@v2
- 해당 레포지토리를 pull 받고 이동하는 action 대부분의 workflow에서 사용uses: actions/setup-node@v2
- 노드를 설치하는 action으로 가상머신안에는 대부분의 프로그래밍 언어가 설치되어 있지 않기 때문에 프로젝트 실행에 필요한 언어들을 action을 통해 다운run: npm install -g bats
- run 키워드를 통해 러너가 실행되는 서버에서 명령어를 실행name: Gradle Build & K8S Deploy
# V를 앞글자로 가지는 태그가 push 될 때 해당 workflow 실행 - ex) V2, V3
on:
push:
tags: V*
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Grant execute permission for gradlew
run : chmod +x gradlew
- name: Build with jib
run: |
./gradlew jib \
-Djib.to.image="zxcvb5434/devopstest:${GITHUB_REF##*/}"
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: update yaml file
run: |
sed -i s/latest/${GITHUB_REF##*/}/ ./k8s/deployment.yaml
cat ./k8s/deployment.yaml
- name: Kubectl apply
uses: steebchen/kubectl@v2.0.0
with:
config: ${{ secrets.KUBECONFIG }}
command: apply -f ./k8s/deployment.yaml
name: Gradle Build & K8S Deploy
on:
push:
tags: V*
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Grant execute permission for gradlew
run : chmod +x gradlew
- name: Build with jib
run: |
./gradlew jib \
-Djib.to.image="zxcvb5434/devopstest:${GITHUB_REF##*/}"
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: update yaml file
run: |
sed -i s/latest/${GITHUB_REF##*/}/ ./k8s/deployment.yaml
cat ./k8s/deployment.yaml
- name: Kubectl apply
uses: steebchen/kubectl@v2.0.0
with:
config: ${{ secrets.KUBECONFIG }}
command: apply -f ./k8s/deployment.yaml