Merge: 2์ฐจ์์ฑ๋ฐฐํฌ #18
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: Build and Deploy | |
on: | |
pull_request: | |
branches: | |
- main | |
types: | |
- closed | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
if: github.event.pull_request.merged == true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set image name with date | |
run: echo "IMAGE_NAME=ticle-client:$(date +'%Y%m%d%H%M')" >> $GITHUB_ENV | |
- name: Check Dockerfile | |
run: | | |
ls -la | |
cat Dockerfile | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }} | |
- name: SSH Remote Commands | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
command_timeout: 200m | |
username: ${{ secrets.USER }} | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }} | |
docker rm -f ticle-client || true | |
docker images -q | xargs -r docker rmi | |
docker run -d -p 3001:80 --name ticle-client ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }} |