Skip to content

Commit

Permalink
Dear 71 pipeline (#28)
Browse files Browse the repository at this point in the history
* DEAR-71 deploy
  • Loading branch information
smuefsmuef authored Jul 19, 2024
1 parent 0a94971 commit daa615d
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 6 deletions.
30 changes: 30 additions & 0 deletions .github/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#docker-compose for server

#version: '3.5'
#services:
# frontend:
# container_name: frontend
# image: ghcr.io/24fsiit16/dear-dev-frontend:latest
# restart: always
# # environment:
# # - AUTH_TRUST_HOST=true
# # - NEXTAUTH_URL=00000001
# ports:
# - "3000:3000"

#backend:
# container_name: backend
# image: ghcr.io/24fsiit16/dear-dev-backend:latest
# ports:
# - "8080:8080"

# nginx:
# container_name: nginx
# image: nginx:latest
# ports:
# - "80:80"
# volumes:
# - ./nginx.conf:/etc/nginx/nginx.conf
# depends_on:
# - frontend
#
53 changes: 53 additions & 0 deletions .github/nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#NGINX

#GNU nano 6.2 nginx.conf *
# events {}
#
# http {
# server {
# listen 80;
# server_name _;
#
# location / {
# proxy_pass http://frontend:3000;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# }
#
# location /api/ {
# proxy_pass http://backend:8080;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# }
# }
#}
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

47 changes: 41 additions & 6 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22'
node-version: '22.4.1'

- name: Clear npm cache
run: npm cache clean --force

- name: Install dependencies
run: npm install
Expand All @@ -30,7 +33,7 @@ jobs:
- name: Run ESLint
run: npm run lint

build_and_push:
build_and_publish:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: test
Expand All @@ -42,7 +45,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22'
node-version: '22.4.1'

- name: Install dependencies
run: npm install
Expand All @@ -60,7 +63,39 @@ jobs:
run: |
REPO_NAME=ghcr.io/${{ github.repository_owner }}/dear-dev-frontend
LOWER_REPO_NAME=$(echo $REPO_NAME | tr '[A-Z]' '[a-z]')
DATE_TAG=$(date +%Y%m%d)
docker build --build-arg SECRET_KEY_NEXT_AUTH=${{ secrets.SECRET_KEY_NEXT_AUTH }} -t $LOWER_REPO_NAME:latest -t $LOWER_REPO_NAME:$DATE_TAG .
docker build --build-arg SECRET_KEY_NEXT_AUTH=${{ secrets.SECRET_KEY_NEXT_AUTH }} -t $LOWER_REPO_NAME:latest .
docker push $LOWER_REPO_NAME:latest
docker push $LOWER_REPO_NAME:$DATE_TAG
deploy:
runs-on: ubuntu-latest
needs: build_and_publish
name: deploy image

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Deploy to server
env:
JWT_SECRET: ${{ secrets.JWT_SECRET }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_ITALIAN_PASSWORD: ${{ secrets.SSH_ITALIAN_PASSWORD }}
SSH_ITALIAN_USER: ${{ secrets.SSH_ITALIAN_USER }}
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} <<'EOF'
echo '${{ secrets.SSH_ITALIAN_PASSWORD }}' | sudo -S su - ${{ secrets.SSH_ITALIAN_USER }} -c '
cd ~/yappi &&
docker-compose stop frontend nginx &&
docker-compose rm frontend nginx &&
docker pull ghcr.io/24FSIIT16/dear-dev-frontend:latest
docker-compose up -d frontend nginx '
EOF
- name: cleanup
run: rm -rf ~/.ssh
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ WORKDIR /app
# Copy the package.json and package-lock.json file
COPY package*.json ./

ARG NEXT_PUBLIC_API_URL

ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}

# Install the dependencies
RUN npm install

Expand Down

0 comments on commit daa615d

Please sign in to comment.