Skip to content

Merge branch 'deploy-node' of https://github.com/elarsaks/gorilla-lab… #15

Merge branch 'deploy-node' of https://github.com/elarsaks/gorilla-lab…

Merge branch 'deploy-node' of https://github.com/elarsaks/gorilla-lab… #15

Workflow file for this run

name: Build and Deploy Node Docker Image to EC2
on:
push:
branches:
- deploy-node
jobs:
build-node-api-image:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Login to Docker Hub
run: echo ${{ secrets.DOCKER_REGISTRY_TOKEN }} | docker login -u ${{ secrets.DOCKER_REGISTRY_USERNAME }} --password-stdin
- name: Build Docker image
run: docker build -t elarsaks/gorilla-labs-api:${{ github.sha }} ./apps/api
- name: Push Docker image to Docker Hub
run: docker push elarsaks/gorilla-labs-api:${{ github.sha }}
deploy-to-ec2:
needs: build-node-api-image
runs-on: ubuntu-latest
steps:
- name: Deploy New Image and Cleanup
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
username: ubuntu
script: |
echo ${{ secrets.DOCKER_REGISTRY_TOKEN }} | docker login -u ${{ secrets.DOCKER_REGISTRY_USERNAME }} --password-stdin
docker pull elarsaks/gorilla-labs-api:${{ github.sha }}
# Stop and remove any existing container (ignore errors if not existing)
docker stop gorilla-labs-api || true
docker rm gorilla-labs-api || true
# Run the new container
docker run -d --restart=always \
--name gorilla-labs-api \
--network gorilla-labs-network \
-p 4000:4000 \
elarsaks/gorilla-labs-api:${{ github.sha }}
# Cleanup unused Docker images
docker image prune -af