Skip to content

Commit e55399e

Browse files
committed
feat : added .github file
1 parent 3efc93f commit e55399e

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

.github/workflows/nextjs.yml renamed to .github/workflows/check_build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Docker Build with pnpm
1+
name: Docker Build
22

33
on:
44
push:
@@ -33,4 +33,4 @@ jobs:
3333
- name: Test if container is running
3434
run: |
3535
sleep 5 # Wait for the container to start
36-
curl -f http://localhost:3000 || exit 1
36+
curl -f http://localhost:3000 || exit 1

.github/workflows/deploy.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Docker Build And Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- prod
7+
pull_request:
8+
branches:
9+
- prod
10+
11+
jobs:
12+
next-build:
13+
name: Build Image
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
steps:
20+
# Step 1: Checkout the code from the repository
21+
- name: Checkout repository
22+
uses: actions/checkout@v3
23+
24+
# Step 2: Set up Docker Buildx for multi-platform builds (optional)
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
# Step 3: Log in to GitHub Container Registry
29+
- name: Log in to GitHub Container Registry
30+
uses: docker/login-action@v2
31+
with:
32+
registry: ghcr.io
33+
username: ${{ secrets.GHCR_USERNAME }}
34+
password: ${{ secrets.GHCR_TOKEN }}
35+
36+
- name: Build and Push Docker Image
37+
env:
38+
ENV_FILE: ${{ secrets.WEBXR_ENV_FILE }}
39+
run: |
40+
echo "$ENV_FILE" > .env
41+
export CURRENT_BRANCH=${GITHUB_REF#refs/heads/}
42+
export TAG=$([[ $CURRENT_BRANCH == $(basename ${{ github.ref }}) ]] && echo $CURRENT_BRANCH || echo "latest")
43+
echo $TAG
44+
export GITHUB_REF_IMAGE=ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA
45+
export GITHUB_BRANCH_IMAGE=ghcr.io/$GITHUB_REPOSITORY:$TAG
46+
export GITHUB_REF_IMAGE=$(echo $GITHUB_REF_IMAGE | tr '[:upper:]' '[:lower:]')
47+
export GITHUB_BRANCH_IMAGE=$(echo $GITHUB_BRANCH_IMAGE | tr '[:upper:]' '[:lower:]')
48+
docker build --build-arg version=$GITHUB_SHA -t $GITHUB_REF_IMAGE -t $GITHUB_BRANCH_IMAGE .
49+
echo "Pushing Image to GitHub Container Registry"
50+
docker push $GITHUB_REF_IMAGE
51+
docker push $GITHUB_BRANCH_IMAGE
52+
rm -rf .env
53+
54+
ghcr-push:
55+
needs: next-build # Job depends on next-build(above) job
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Deploy on Production server
59+
if: github.ref == 'refs/heads/prod'
60+
uses: appleboy/[email protected]
61+
with:
62+
host: ${{ secrets.REMOTE_SERVER_ADDRESS }}
63+
username: ${{ secrets.SERVER_USERNAME }}
64+
key: ${{ secrets.REMOTE_SERVER_KEY }}
65+
port: ${{ secrets.SSH_PORT }}
66+
script: |
67+
pwd
68+
cd ~
69+
sudo docker stop webxr && sudo docker rm webxr && sudo docker rmi webxr
70+
echo ${{ secrets.GHCR_TOKEN }} | sudo docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
71+
sudo docker pull ghcr.io/myriadflow/webxr:prod
72+
sudo docker run --name="webxr" -p 8080:3002 -d ghcr.io/myriadflow/webxr:prod

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ yarn-error.log*
2727
# local env files
2828
.env*.local
2929
.env
30+
.env.example
3031

3132
# vercel
3233
.vercel

0 commit comments

Comments
 (0)