Skip to content

Merge branch 'main' #67

Merge branch 'main'

Merge branch 'main' #67

Workflow file for this run

name: spurt CICD
on:
push:
branches:
- master
jobs:
push_to_registry:
name: Push to ncp container registry
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build -x spotlessJavaCheck
cache-read-only: ${{ github.ref != 'refs/heads/master' }}
- name: save docs file
uses: actions/upload-artifact@v3
with:
name: api-docs
path: build/docs/asciidoc
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to NCP Container Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }}
username: ${{ secrets.NCP_ACCESS_KEY }}
password: ${{ secrets.NCP_SECRET_KEY }}
- name: docker build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/spurt-backend:latest
cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/spurt-backend:latest
cache-to: type=inline
secrets: |
GIT_AUTH_TOKEN=${{ secrets.GIT_TOKEN }}
pull_from_registry:
name: Connect server ssh and pull from container registry
needs: push_to_registry
runs-on: ubuntu-latest
steps:
- name: connect ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEV_HOST }}
username: ${{ secrets.DEV_USERNAME }}
password: ${{ secrets.DEV_PASSWORD }}
port: ${{ secrets.DEV_PORT }}
script: |
docker login ${{ secrets.NCP_CONTAINER_REGISTRY }} -u ${{ secrets.NCP_ACCESS_KEY }} -p ${{ secrets.NCP_SECRET_KEY }}
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/spurt-backend:latest
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker run -d -p 8080:8080 ${{ secrets.NCP_CONTAINER_REGISTRY }}/spurt-backend:latest
docker image prune -f
upload_docs:
name: upload api docs
needs: pull_from_registry
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: api-docs # Artifact name
path: artifact
- name: Upload Files to S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.NCP_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.NCP_SECRET_KEY }}
AWS_DEFAULT_REGION: us-east-1
run: |
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp artifact/index.html s3://spurt-backend-docs
aws --endpoint-url=https://kr.object.ncloudstorage.com/ s3 ls s3://spurt-backend-docs --recursive | awk '{cmd="aws --endpoint-url=https://kr.object.ncloudstorage.com/ s3api put-object-acl --bucket spurt-backend-docs --acl public-read --key "$4; system(cmd)}'