docker cicd #4
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 | |
- name: Run chmod to make gradlew executable | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build --exclude-task 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 }} . | |
# docker build -t ${{ secrets.DOCKER_IMAGE_NAME }} . | |
# docker push ${{ 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 pull ${{ secrets.DOCKER_IMAGE_NAME }} | |
sudo docker stop chat-server | |
sudo docker run -d --rm --name chat-server -p 8080:8080 ${{ secrets.DOCKER_IMAGE_NAME }} |