Skip to content

Commit

Permalink
docker config
Browse files Browse the repository at this point in the history
  • Loading branch information
kayprogrammer committed Aug 18, 2024
1 parent 2c9167a commit 42b6227
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 12 deletions.
21 changes: 21 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Ignore Flutter build outputs
build/
.flutter/
.dart_tool/
.packages

# Ignore node_modules if you have any
node_modules/

# Ignore editor settings
.idea/
.vscode/
*.iml

# Ignore OS-specific files
.DS_Store
Thumbs.db

# Ignore git files
.git
.gitignore
65 changes: 65 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Deploy Frontend to VPS

on:
push:
branches:
- dev-jeremy

env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock

jobs:
deploy:
runs-on: ubuntu-latest

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

- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y sshpass expect rsync
- name: Setup SSH passphrase
env:
SSH_PASSPHRASE: ${{ secrets.SSH_PASSPHRASE }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
echo 'echo $SSH_PASSPHRASE' > ~/.ssh_askpass && chmod +x ~/.ssh_askpass
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | DISPLAY=None SSH_ASKPASS=~/.ssh_askpass ssh-add - >/dev/null
echo "SSH key added"
- name: Verify SSH Connection
env:
VPS_IP: ${{ secrets.VPS_IP }}
run: |
sshpass -p "${{ secrets.SSH_PASSPHRASE }}" ssh -o StrictHostKeyChecking=no docker@${VPS_IP} "echo Connection successful"
- name: Install rsync on VPS
env:
VPS_IP: ${{ secrets.VPS_IP }}
run: |
sshpass -p "${{ secrets.SSH_PASSPHRASE }}" ssh -o StrictHostKeyChecking=no docker@${VPS_IP} << 'EOF'
sudo apt-get update
sudo apt-get install -y rsync
EOF
- name: Copy files to VPS
env:
VPS_IP: ${{ secrets.VPS_IP }}
run: |
sshpass -p "${{ secrets.SSH_PASSPHRASE }}" rsync -avz -e "ssh -o StrictHostKeyChecking=no" ./ docker@${VPS_IP}:/frontend
echo "Files copied to VPS"
- name: SSH and run Docker Compose
env:
VPS_IP: ${{ secrets.VPS_IP }}
run: |
sshpass -p "${{ secrets.SSH_PASSPHRASE }}" ssh -o StrictHostKeyChecking=no docker@${VPS_IP} << 'EOF'
cd /frontend
docker-compose down
docker-compose up -d --build
echo "Docker Compose executed"
EOF
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Stage 1: Build the Flutter web project
FROM cirrusci/flutter:3.10.6 as build

# Set working directory
WORKDIR /app

# Copy the Flutter project files
COPY . .

# Ensure dependencies are installed
RUN flutter pub get

# Build the project for web
RUN flutter build web --release

# Stage 2: Serve the static files with nginx
FROM nginx:stable-alpine

# Copy the built files from the previous stage
COPY --from=build /app/build/web /usr/share/nginx/html

# Change the default nginx port to 3000
RUN sed -i 's/listen .*/listen 3000;/' /etc/nginx/conf.d/default.conf

# Expose the new port
EXPOSE 3000

# Start nginx server
CMD ["nginx", "-g", "daemon off;"]
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ifneq (,$(wildcard ./.env))
include .env
export
ENV_FILE_PARAM = --env-file .env

endif

build:
docker-compose up -d --build
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.8'

services:
flutter-web:
build: .
ports:
- "3000:3000"
restart: always
56 changes: 44 additions & 12 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.9.0"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
source: hosted
version: "10.0.4"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
lints:
dependency: transitive
description:
Expand All @@ -444,26 +468,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.12.0"
nested:
dependency: transitive
description:
Expand All @@ -476,10 +500,10 @@ packages:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
path_parsing:
dependency: transitive
description:
Expand Down Expand Up @@ -641,10 +665,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
url: "https://pub.dev"
source: hosted
version: "0.6.1"
version: "0.7.0"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -773,6 +797,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
version: "14.2.1"
web:
dependency: transitive
description:
Expand Down Expand Up @@ -814,5 +846,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.2.6 <4.0.0"
flutter: ">=3.16.6"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"

0 comments on commit 42b6227

Please sign in to comment.