From 9cbb405ba045463b4a46233908a0958e148e7fb2 Mon Sep 17 00:00:00 2001 From: Bayda77 Date: Sat, 3 Jan 2026 17:04:43 -0600 Subject: [PATCH] feat: Add Dockerfile, Nginx configuration, and GitHub Actions workflow for continuous deployment. --- .github/workflows/deploy.yml | 75 ++++++++++++++++++++++++++++++++++++ Dockerfile | 20 ++++++++++ nginx.conf | 14 +++++++ 3 files changed, 109 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..2420e15 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,75 @@ +name: Deploy to Production + +on: + push: + branches: [ "main" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + deploy: + runs-on: ubuntu-latest + needs: build-and-push + steps: + - name: Deploy to Remote Server + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.REMOTE_HOST }} + username: ${{ secrets.REMOTE_USER }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + script: | + # Login to registry + echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + # Pull new image + docker pull ghcr.io/${{ env.IMAGE_NAME }}:latest + + # Stop and remove existing container + docker stop resume-frontend || true + docker rm resume-frontend || true + + # Run new container + docker run -d \ + --name resume-frontend \ + --restart unless-stopped \ + -p 80:80 \ + ghcr.io/${{ env.IMAGE_NAME }}:latest + + # Cleanup unused images + docker image prune -f diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5bf06e0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Build stage +FROM node:18-alpine as build + +WORKDIR /app + +COPY package*.json ./ +RUN npm ci + +COPY . . +RUN npm run build + +# Production stage +FROM nginx:alpine + +COPY --from=build /app/build /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..a45f3f9 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,14 @@ +server { + listen 80; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} -- 2.49.1