Skip to content

Commit

Permalink
Develop (#52)
Browse files Browse the repository at this point in the history
* Updae build folder

* Use node 20

* Build image on prod

* Refactor workflows

* Fix matrix error
  • Loading branch information
nyatindopatrick authored Sep 26, 2024
1 parent 9e8d4b5 commit 9a95768
Showing 1 changed file with 15 additions and 46 deletions.
61 changes: 15 additions & 46 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
name: React App Deployment

on:
push:
branches:
- main
- develop
branches: [main, develop]
workflow_dispatch:
inputs:
environment:
description: "Environment to deploy"
required: true
type: choice
options:
- production
- Dev

jobs:
build_and_deploy_dev:
if: github.ref == 'refs/heads/develop'
deploy:
runs-on: ubuntu-latest
environment: Dev
environment: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || (github.ref == 'refs/heads/main' && 'production' || 'Dev') }}

steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -38,46 +45,8 @@ jobs:
tags: ${{ secrets.DOCKER_USERNAME }}/chanjokeclient:latest
build-args: |
VITE_SERVER_BASE_URL=${{ secrets.VITE_SERVER_BASE_URL }}
- name: Deploy to Dev server
env:
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
run: |
echo "$SSH_PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << EOF
CONTAINER_NAME=chanjoke
IMAGE_NAME=${{ secrets.DOCKER_USERNAME }}/chanjokeclient:latest
if docker ps -a --format '{{.Names}}' | grep -q \$CONTAINER_NAME; then
echo "Stopping and removing existing container"
docker stop \$CONTAINER_NAME || true
docker rm \$CONTAINER_NAME || true
fi
echo '${{ secrets.DOCKER_PASSWORD }}' | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
if [ \$? -ne 0 ]; then
echo "Error: Docker login failed"
exit 1
fi
docker pull --quiet \$IMAGE_NAME
if [ \$? -ne 0 ]; then
echo "Error: Failed to pull Docker image \$IMAGE_NAME"
exit 1
fi
sudo docker run -d --name \$CONTAINER_NAME -p 8098:3000 \$IMAGE_NAME
sudo docker logout
echo "Dev deployment completed successfully"
EOF
rm -f private_key
deploy_prod:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production
steps:
- name: Deploy to Production server
- name: Deploy to server
env:
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
run: |
Expand Down Expand Up @@ -107,6 +76,6 @@ jobs:
sudo docker run -d --name \$CONTAINER_NAME -p 8098:3000 \$IMAGE_NAME
sudo docker logout
echo "Production deployment completed successfully"
echo "${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || (github.ref == 'refs/heads/main' && 'production' || 'Dev') }} deployment completed successfully"
EOF
rm -f private_key

0 comments on commit 9a95768

Please sign in to comment.