diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..289f4e1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,35 @@ +# Dependencies +node_modules +npm-debug.log* + +# Build outputs +dist +dist-ssr +*.local + +# Git +.git +.gitignore + +# IDE +.vscode +.idea +*.swp +*.swo +.DS_Store + +# Testing +coverage +.nyc_output + +# Documentation +README.md +*.md + +# CI/CD +.gitea + +# Other +*.log +.cache + diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index d2d2720..69e75c2 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -2,54 +2,33 @@ name: Deploy to Private Server on: push: - branches: [ "main" ] + branches: ["main"] jobs: - build: - runs-on: ubuntu-latest - container: - image: node:20-slim - - steps: - - uses: actions/checkout@v4 - - - name: Build Vite app - run: | - npm ci - npm run build - - - name: Upload build artifacts - uses: actions/upload-artifact@v3 - with: - name: build-output - path: dist/ - deploy: runs-on: homesrv - needs: build - steps: - - name: Load NVM and Node - run: | - bash -lc ' - export NVM_DIR="/root/.nvm" - source "$NVM_DIR/nvm.sh" - node -v - npm -v - ' + steps: - uses: actions/checkout@v4 - - name: Download build artifacts - uses: actions/download-artifact@v3 - with: - name: build-output - path: dist/ - - - name: Deploy to host + - name: Build Docker image run: | - rm -rf /www/vite-app/timelapse-calc - mkdir -p /www/vite-app/timelapse-calc - cp -r dist/* /www/vite-app/timelapse-calc/ - echo "Deployment completed successfully" - echo "Deployed files:" - ls -la /www/vite-app/timelapse-calc/ \ No newline at end of file + docker build -t timelapse-calc:latest \ + -f Dockerfile . + + - name: Stop old container if exists + run: | + if docker ps -a --format '{{.Names}}' | grep -q '^timelapse-calc$'; then + docker stop timelapse-calc + docker rm timelapse-calc + fi + + - name: Run new container + run: | + docker run -d \ + --restart always \ + --name timelapse-calc \ + -p 3005:80 \ + timelapse-calc:latest + + docker ps --format "{{.Names}} {{.Image}} {{.Status}}" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f4e27ac --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +# Build stage +FROM node:20-alpine AS build + +WORKDIR /app + +# Copy package files +COPY package.json package-lock.json ./ + +# Install dependencies +RUN npm ci + +# Copy source code +COPY . . + +# Build the application +RUN npm run build + +# Production stage +FROM nginx:alpine + +# Copy built assets from build stage +COPY --from=build /app/dist /usr/share/nginx/html + +RUN echo 'server { \ + listen 80; \ + server_name _; \ + root /usr/share/nginx/html; \ + index index.html; \ + location / { \ + try_files $uri $uri/ /index.html; \ + } \ + # Cache static assets \ + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { \ + expires 1y; \ + add_header Cache-Control "public, immutable"; \ + } \ +}' > /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"]