diff --git a/.github/docker-compose.yml b/.github/docker-compose.yml new file mode 100644 index 0000000..546034a --- /dev/null +++ b/.github/docker-compose.yml @@ -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 +# diff --git a/.github/nginx.yml b/.github/nginx.yml new file mode 100644 index 0000000..79ac94f --- /dev/null +++ b/.github/nginx.yml @@ -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; +# } +# } +#} +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# + diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 30c3c99..dd2055f 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -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 @@ -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 @@ -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 @@ -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/ssh-agent@v0.5.3 + 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 diff --git a/Dockerfile b/Dockerfile index 9629388..1821cfb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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