Merge pull request #184 from dnd-side-project/fix/#182 #50
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
name: CI/CD using GitHub Actions & Docker | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
CI-CD: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Create directory and file if not exist | |
run: | | |
mkdir -p ./src/main/resources | |
echo "${{ secrets.APPLICATION_PROD }}" > ./src/main/resources/application-prod.yml | |
echo "cors:" >> ./src/main/resources/application-prod.yml | |
echo " allowed-origin: ${{ secrets.ALLOWED_ORIGIN }}" >> ./src/main/resources/application-prod.yml | |
echo " max-age: 2400" >> ./src/main/resources/application-prod.yml | |
- name: Set executable permission | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
- name: Docker build & push to prod | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT . | |
docker push ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT | |
- name: Deploy to prod | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST_PROD }} | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} | |
envs: GITHUB_SHA | |
script: | | |
sudo docker stop spaced || true | |
sudo docker rm spaced || true | |
sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT | |
sudo docker run -d -p 8080:8080 --name spaced ${{ secrets.DOCKER_USERNAME }}/spaced:0.0.1-SNAPSHOT \ | |
--spring.profiles.active=prod |