Skip to content

[ADD] Github action for deploy #1

[ADD] Github action for deploy

[ADD] Github action for deploy #1

Workflow file for this run

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;