Merge pull request #94 from Dan-sup/feat/danceclass #93
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: Deploy to EC2 | |
on: | |
push: | |
branches: [ "develop" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: Cache Gradle packages | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} | |
restore-keys: ${{ runner.os }}-gradle- | |
- name: Create Env File | |
run: | | |
touch .env | |
echo "${{ secrets.ENV_VARS }}" >> .env | |
- name: Make application-db.yml | |
run: | | |
cd ./src/main/resources | |
echo "${{ secrets.DATABASE }}" >> ./application-db.yml | |
shell: bash | |
- name: Make application-oauth.yml | |
run: | | |
cd ./src/main/resources | |
echo "${{ secrets.OAUTH }}" >> ./application-oauth.yml | |
shell: bash | |
- name: Make application-security.yml | |
run: | | |
cd ./src/main/resources | |
echo "${{ secrets.SECURITY }}" >> ./application-security.yml | |
shell: bash | |
- name: Make application-s3.yml | |
run: | | |
cd ./src/main/resources | |
echo "${{ secrets.S3 }}" >> ./application-s3.yml | |
shell: bash | |
- name: Make application-redis.yml | |
run: | | |
cd ./src/main/resources | |
echo "${{ secrets.REDIS }}" >> ./application-redis.yml | |
shell: bash | |
- name: Build with Gradle | |
run: | | |
chmod +x ./gradlew | |
./gradlew clean build -x test | |
- name: Docker Build and Push | |
run: | | |
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
sudo docker build -t ${{ secrets.DOCKER_REPO }}/dansup-web . | |
sudo docker push ${{ secrets.DOCKER_REPO }}/dansup-web | |
sudo docker build -f ./config/nginx/Dockerfile -t ${{ secrets.DOCKER_REPO }}/dansup-nginx . | |
sudo docker push ${{ secrets.DOCKER_REPO }}/dansup-nginx | |
- name: Create Remote Directory | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.KEY }} | |
script: mkdir -p ~/srv/ubuntu | |
- name: copy source via ssh key | |
uses: burnett01/[email protected] | |
with: | |
switches: -avzr --delete | |
remote_path: ~/srv/ubuntu | |
remote_host: ${{ secrets.HOST }} | |
remote_user: ubuntu | |
remote_key: ${{ secrets.KEY }} | |
- name: executing remote ssh commands using password | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.KEY }} | |
script: | | |
sh ~/srv/ubuntu/config/scripts/deploy.sh | |
cd /home/ubuntu/srv/ubuntu/ | |
sudo chmod 666 /var/run/docker.sock | |
sudo docker rm -f $(sudo docker ps -qa) | |
sudo docker pull ${{ secrets.DOCKER_REPO }}/dansup-web | |
sudo docker pull ${{ secrets.DOCKER_REPO }}/dansup-nginx | |
sudo docker pull redis | |
docker-compose up -d | |
docker image prune -f |