Skip to content

Commit

Permalink
feat : added .github file
Browse files Browse the repository at this point in the history
surajhub255 committed Oct 26, 2024
1 parent 3efc93f commit e55399e
Showing 3 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker Build with pnpm
name: Docker Build

on:
push:
@@ -33,4 +33,4 @@ jobs:
- name: Test if container is running
run: |
sleep 5 # Wait for the container to start
curl -f http://localhost:3000 || exit 1
curl -f http://localhost:3000 || exit 1
72 changes: 72 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Docker Build And Deploy

on:
push:
branches:
- prod
pull_request:
branches:
- prod

jobs:
next-build:
name: Build Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
# Step 1: Checkout the code from the repository
- name: Checkout repository
uses: actions/checkout@v3

# Step 2: Set up Docker Buildx for multi-platform builds (optional)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Step 3: Log in to GitHub Container Registry
- name: Log in 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
env:
ENV_FILE: ${{ secrets.WEBXR_ENV_FILE }}
run: |
echo "$ENV_FILE" > .env
export CURRENT_BRANCH=${GITHUB_REF#refs/heads/}
export TAG=$([[ $CURRENT_BRANCH == $(basename ${{ github.ref }}) ]] && echo $CURRENT_BRANCH || echo "latest")
echo $TAG
export GITHUB_REF_IMAGE=ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA
export GITHUB_BRANCH_IMAGE=ghcr.io/$GITHUB_REPOSITORY:$TAG
export GITHUB_REF_IMAGE=$(echo $GITHUB_REF_IMAGE | tr '[:upper:]' '[:lower:]')
export GITHUB_BRANCH_IMAGE=$(echo $GITHUB_BRANCH_IMAGE | tr '[:upper:]' '[:lower:]')
docker build --build-arg version=$GITHUB_SHA -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
rm -rf .env
ghcr-push:
needs: next-build # Job depends on next-build(above) job
runs-on: ubuntu-latest
steps:
- name: Deploy on Production server
if: github.ref == 'refs/heads/prod'
uses: appleboy/[email protected]
with:
host: ${{ secrets.REMOTE_SERVER_ADDRESS }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.REMOTE_SERVER_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
pwd
cd ~
sudo docker stop webxr && sudo docker rm webxr && sudo docker rmi webxr
echo ${{ secrets.GHCR_TOKEN }} | sudo docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
sudo docker pull ghcr.io/myriadflow/webxr:prod
sudo docker run --name="webxr" -p 8080:3002 -d ghcr.io/myriadflow/webxr:prod
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ yarn-error.log*
# local env files
.env*.local
.env
.env.example

# vercel
.vercel

0 comments on commit e55399e

Please sign in to comment.