Skip to content

fix: cd-script & Dockerfile (#14) #1

fix: cd-script & Dockerfile (#14)

fix: cd-script & Dockerfile (#14) #1

Workflow file for this run

name: api-cd
on:
push:
branches: [ "dev" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: make .env
run: |
touch ./.env
echo "${{ secrets.ENV }}" > ./.env
- name: SCP transfer
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.NCP_USERNAME }}
password: ${{ secrets.NCP_PASSWORD }}
port: ${{ secrets.NCP_PORT }}
source: ${{ secrets.SOURCE_PATH }}
target: ${{ secrets.DIST_PATH }}
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build -x test
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t app .
docker tag app ${{ secrets.DOCKER_USERNAME }}/linker:latest
docker push ${{ secrets.DOCKER_USERNAME }}/linker:latest
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }} # NCP 서버접속용 공인 IP
username: ${{ secrets.NCP_USERNAME }} # instance user
password: ${{ secrets.NCP_PASSWORD }} # instance pw
port: ${{ secrets.NCP_PORT }} # port
script: | # docker compose deploy
cd /home/linker
docker-compose -f docker-compose.dev.yml down
docker pull ${{ secrets.DOCKER_USERNAME }}/linker:latest
docker-compose -f docker-compose.dev.yml up --build -d
docker rm $(docker ps --filter 'status=exited' -a -q)
docker image prune -a -f