Merge pull request #115 from catchroom/develop #101
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# github repository actions νμ΄μ§μ λνλ μ΄λ¦ | |
name: CI/CD using github actions & docker | |
# event trigger | |
# main λΈλμΉμ pushκ° λμμ λ μ€ν | |
on: | |
push: | |
branches: [ "main" ] | |
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: Create application.yml | |
run: | | |
mkdir -p src/main/resources | |
echo "${{ secrets.APPLICATION_YML }}" > src/main/resources/application.yml | |
cat ./src/main/resources/application.yml | |
echo "${{ secrets.DOCKER-COMPOSE }}" > docker-compose.yml | |
cat docker-compose.yml | |
- name: Run chmod to make gradlew executable | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
- name: Docker build | |
run: | | |
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PWD }} | |
docker buildx build --push --platform linux/amd64 -t ${{ secrets.DOCKER_IMAGE_NAME }} . | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USER_NAME }} | |
key: ${{ secrets.PRIVATE_KEY }} | |
script: | | |
sudo docker stop prod1 | |
sudo docker stop prod2 | |
sudo docker pull ${{ secrets.DOCKER_IMAGE_NAME }} | |
docker-compose up -d | |
sudo docker image prune -af | |
# sleep 10 | |
# sudo docker stop chat-server-2 | |
# sudo docker run -d --rm --name chat-server-2 -p 8082:8080 ${{ secrets.DOCKER_IMAGE_NAME }} |