[ADD] Github action for deploy #1
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 GST Beta to Server | |
on: | |
push: | |
branches: | |
- beta | |
env: | |
APP_TAG: beta | |
PORT: 3295 | |
jobs: | |
buildDockerImage: | |
runs-on: ubuntu-latest | |
name: Build/Push Docker image | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Build Docker image | |
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/gst-api:$APP_TAG . | |
- name: Login to Docker Hub | |
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
- name: Set Docker image tag | |
run: docker tag ${{ secrets.DOCKER_USERNAME }}/gst-api:$APP_TAG ${{ secrets.DOCKER_USERNAME }}/gst-api:$APP_TAG | |
- name: Push Docker image | |
run: docker push ${{ secrets.DOCKER_USERNAME }}/gst-api:$APP_TAG | |
deploy: | |
runs-on: ubuntu-latest | |
name: Continuous Deployment | |
needs: [buildDockerImage] | |
steps: | |
- name: Deploy using ssh | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
port: 22 | |
envs: APP_TAG, PORT | |
script: | | |
docker stop gst-api-$APP_TAG; | |
docker rm gst-api-$APP_TAG; | |
docker pull ${{ secrets.DOCKER_USERNAME }}/gst-api:$APP_TAG; | |
docker run -d --name gst-api-$APP_TAG -p $PORT:3000 --network ${{ secrets.DOCKER_NETWORK }} --restart unless-stopped --env-file ${{ secrets.ENV_PATH }} ${{ secrets.DOCKER_USERNAME }}/gst-api:$APP_TAG; |