Deploy : test #19
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: action | |
on: | |
push: | |
branches: | |
- deploy | |
jobs: | |
sync-to-gitlab: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
path: authentication | |
- name: Configure Git | |
run: | | |
git config --global user.name "신창엽" | |
git config --global user.email "[email protected]" | |
- name: Install rsync | |
run: sudo apt-get install rsync | |
- name: Configure merge strategy for pull | |
run: git config --global pull.rebase false | |
- name: Sync to Gitlab | |
env: | |
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} | |
run: | | |
git clone --branch authentication https://oauth2:[email protected]/s10-bigdata-recom-sub2/S10P22D204.git S10P22D204 | |
mkdir -p S10P22D204/authentication | |
rsync -av --delete --exclude='.git/' --exclude='.github/' --exclude='./Dockerfile' --exclude='./docker-compose.yml' ./authentication/ S10P22D204/authentication/ | |
cd S10P22D204 | |
git add authentication/ | |
git_status=$(git status --porcelain) | |
if [ ! -z "$git_status" ]; then | |
git commit -m "authentication server develop update" | |
git push origin authentication --force | |
else | |
echo "No changes to commit." | |
fi | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/auth | |
deploy: | |
needs: build-and-push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USER }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: | | |
cd /home/ubuntu/project/auth | |
git pull | |
docker stop auth | |
docker rm auth | |
docker run --name auth -d \ | |
-p 8081:8081 \ | |
--network=bridge \ | |
--restart unless-stopped \ | |
${DOCKERHUB_USERNAME}/auth | |
docker container prune -f | |
docker image prune -f | |