Skip to content

Commit

Permalink
adding ci cd
Browse files Browse the repository at this point in the history
  • Loading branch information
p-shubh committed Jun 26, 2024
1 parent 20fe435 commit 99e1625
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "Build and Push to GHCR"

on:
push:
branches:
- main

jobs:

Deploy:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Build and Push Docker Image
run: |
export CURRENT_BRANCH=${GITHUB_REF#refs/heads/}
export TAG=$([[ $CURRENT_BRANCH == $(basename ${{ github.ref }}) ]] && echo $CURRENT_BRANCH || echo "latest")
export GITHUB_REF_IMAGE=ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA
export GITHUB_BRANCH_IMAGE=ghcr.io/$GITHUB_REPOSITORY:$TAG
docker build -t $GITHUB_REF_IMAGE -t $GITHUB_BRANCH_IMAGE .
echo "Pushing Image to GitHub Container Registry"
docker push $GITHUB_REF_IMAGE
docker push $GITHUB_BRANCH_IMAGE

- name: Deploy on DEV server
if: github.ref == 'refs/heads/main'
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEV_REMOTE_SERVER_ADDRESS }}
username: ${{ secrets.DEV_SERVER_USERNAME }}
key: ${{ secrets.DEV_REMOTE_SERVER_KEY }}
port: ${{ secrets.DEV_SSH_PORT }}
script: |
pwd
cd app.gateway
sudo docker stop myriadflow_gateway && sudo docker rm myriadflow_gateway && sudo docker image rm ghcr.io/MyriadFlow/app.myriadflow:main
echo ${{ secrets.GHCR_TOKEN }} | sudo docker login ghcr.io -u secrets.GHCR_USERNAME --password-stdin
sudo docker pull ghcr.io/MyriadFlow/app.myriadflow.com:main
sudo docker run --name="myriadflow_gateway" --env-file=.env -p 9079:8080 --net=bridge -d ghcr.io/MyriadFlow/app.myriadflow:main

0 comments on commit 99e1625

Please sign in to comment.