Skip to content

Commit

Permalink
deploy to docker
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lvax committed Oct 10, 2024
1 parent bb743ca commit 2dc2287
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 5 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy App

on:
push:
branches:
- main # or your deployment branch

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Copy repository to SFTP
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SFTP_HOST }}
username: ${{ secrets.SFTP_USER }}
password: ${{ secrets.SFTP_PASSWORD }}
port: ${{ secrets.SFTP_PORT }}
source: '.'
target: '/opt/route'

- name: Build and deploy Docker container
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SFTP_HOST }}
username: ${{ secrets.SFTP_USER }}
password: ${{ secrets.SFTP_PASSWORD }}
port: ${{ secrets.SFTP_PORT }}
script: |
cd '/opt/route'
# Overwrite the .env file to recreate it during each deployment
echo "AUTH_SECRET=${{ secrets.AUTH_SECRET }}" > .env
echo "CLIENT_ID=${{ secrets.CLIENT_ID }}" >> .env
echo "CLIENT_SECRET=${{ secrets.CLIENT_SECRET }}" >> .env
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> .env
docker build -t route .
docker stop route || true
docker rm route || true
docker run -d --name route --restart always -p 3002:3000 route
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Builder stage
FROM node:21-alpine AS builder
WORKDIR /app

# Install pnpm
RUN npm install -g pnpm

# Copy package files and install dependencies
COPY package*.json ./
RUN pnpm install

# Copy the rest of the files and build the application
COPY . .
RUN pnpm run build

# Prune development dependencies
RUN pnpm prune --prod

# Final stage
FROM node:21-alpine
WORKDIR /app

# Copy necessary files from builder stage
COPY --from=builder /app/build build/
COPY --from=builder /app/node_modules node_modules/
COPY package.json .

# Set the environment and expose the port
EXPOSE 3000
ENV NODE_ENV=production

# Command to run the application
CMD [ "node", "build" ]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/adapter-cloudflare": "^4.7.2",
"@sveltejs/adapter-node": "^5.2.6",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@tailwindcss/typography": "^0.5.14",
Expand Down
125 changes: 121 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adapter from '@sveltejs/adapter-cloudflare';
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
Expand Down

0 comments on commit 2dc2287

Please sign in to comment.