#170 An author will be able to update a blog (#171) #71
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: Docker Build and Deploy | |
on: | |
push: | |
branches: | |
- develop | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
env: | |
MONGO_PROD_DB: ${{ secrets.MONGO_PROD_DB }} | |
FRONTEND_LINK: "https://applications.devpulse.org" | |
NODE_ENV: "production" | |
PUSHER_CLUSTER: ${{ secrets.PUSHER_CLUSTER }} | |
PUSHER_APP_ID: ${{ secrets.PUSHER_APP_ID }} | |
PUSHER_KEY: ${{ secrets.PUSHER_KEY }} | |
PUSHER_SECRET: ${{ secrets.PUSHER_SECRET }} | |
DEVPULSE_EMAIL: ${{ secrets.DEVPULSE_EMAIL }} | |
API_KEY: ${{ secrets.API_KEY }} | |
SENDER_NAME: ${{ secrets.SENDER_NAME }} | |
PORT: ${{ secrets.PORT }} | |
JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Build and push Docker image | |
uses: mr-smithers-excellent/docker-build-push@v6 | |
with: | |
image: ${{ secrets.DOCKER_HUB_USERNAME2 }}/atlp-devpulse-bn | |
tags: latest | |
registry: docker.io | |
username: ${{ secrets.DOCKER_HUB_USERNAME2 }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD2 }} | |
buildArgs: 'NODE_ENV=production, MONGO_PROD_DB="${{ secrets.MONGO_PROD_DB }}"' | |
- name: Deploy to DigitalOcean | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.DO_HOST }} | |
username: ${{ secrets.DO_USERNAME }} | |
key: ${{ secrets.DO_KEY }} | |
port: ${{ secrets.DO_PORT }} | |
envs: MONGO_PROD_DB,REGISTER_FRONTEND_URL,REGISTER_ORG_FRONTEND_URL,NODE_ENV,FRONTEND_LINK,ADMIN_EMAIL,ADMIN_PASS,COORDINATOR_EMAIL,COORDINATOR_PASS,GH_TOKEN, PUSHER_CLUSTER, PUSHER_APP_ID, PUSHER_KEY, PUSHER_SECRET, API_KEY, SENDER_NAME, DEVPULSE_EMAIL, PORT, JWT_SECRET | |
script: | | |
touch env | |
echo "MONGO_PROD_DB=${MONGO_PROD_DB}" > env | |
echo "FRONTEND_LINK=${FRONTEND_LINK}" >> env | |
echo "NODE_ENV=${NODE_ENV}" >> env | |
echo "PUSHER_CLUSTER=${PUSHER_CLUSTER}" >> env | |
echo "PUSHER_APP_ID=${PUSHER_APP_ID}" >> env | |
echo "PUSHER_KEY=${PUSHER_KEY}" >> env | |
echo "PUSHER_SECRET=${PUSHER_SECRET}" >> env | |
echo "DEVPULSE_EMAIL=${DEVPULSE_EMAIL}" >> env | |
echo "API_KEY=${API_KEY}" >> env | |
echo "SENDER_NAME=${SENDER_NAME}" >> env | |
echo "PORT=${PORT}" >> env | |
echo "JWT_SECRET=${JWT_SECRET}" >> env | |
# Pull the latest image | |
docker pull ${{ secrets.DOCKER_HUB_USERNAME2 }}/atlp-devpulse-bn:latest | |
# Stop and remove existing container if it exists | |
docker stop $(docker ps -q --filter publish=4008) || true | |
docker rm $(docker ps -aq --filter publish=4008) || true | |
# Run new container | |
output=$( docker run -d \ | |
-p 4008:5000 \ | |
--env-file env \ | |
${{ secrets.DOCKER_HUB_USERNAME2 }}/atlp-devpulse-bn:latest) | |
echo $output | |
echo "Container ID: $output" | |
if [ -z "$output" ]; then | |
echo "Container failed to start" | |
exit 1 | |
fi | |