From fb00a75110523bb8147fd690dcf5523827c8572b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 19 May 2025 07:28:09 +0000 Subject: [PATCH] setting server --- .github/workflows/deploy.yml | 34 ++++++++++++++++++++++++++++ Dockerfile | 29 ++++++++++++++++++++++++ docker-compose.yml | 43 ++++++++++++++++++++++++++++++++++++ nginx/default.conf | 21 ++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx/default.conf diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..9f2af8a --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,34 @@ +name: Deploy Laravel to VPS via Docker + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + + - name: Copy files via SSH to VPS + uses: appleboy/scp-action@v0.1.4 + with: + host: ${{ secrets.VPS_HOST }} + username: ${{ secrets.VPS_USER }} + key: ${{ secrets.VPS_SSH_KEY }} + source: "." + target: "/home/${{ secrets.VPS_USER }}/laravel-app" + + - name: SSH to VPS and restart container + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.VPS_HOST }} + username: ${{ secrets.VPS_USER }} + key: ${{ secrets.VPS_SSH_KEY }} + script: | + cd laravel-app + docker-compose down + docker-compose up -d --build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ee09a88 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM php:8.2-fpm + +# Install dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + libpng-dev \ + libonig-dev \ + libxml2-dev \ + zip \ + unzip \ + curl \ + git \ + nodejs \ + npm + +# Install PHP extensions +RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd + +# Install Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +WORKDIR /var/www + +COPY . . + +RUN composer install +RUN npm install && npm run build + +CMD ["php-fpm"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..04af2a6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,43 @@ +version: '3.8' +services: + app: + build: + context: . + dockerfile: Dockerfile + container_name: laravel_app + volumes: + - .:/var/www + depends_on: + - mysql + networks: + - laravel + + mysql: + image: mysql:8 + container_name: laravel_db + restart: always + environment: + MYSQL_DATABASE: db_presensi + MYSQL_PASSWORD: 12345678 + MYSQL_USER: root + ports: + - "3306:3306" + networks: + - laravel + + nginx: + image: nginx:latest + container_name: laravel_nginx + ports: + - "80:80" + volumes: + - .:/var/www + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + depends_on: + - app + networks: + - laravel + +networks: + laravel: + driver: bridge diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..a49a152 --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,21 @@ +server { + listen 80; + index index.php index.html; + server_name dkvsmkn4jember.my.id; + root /var/www/smk4-web/public; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + fastcgi_pass app:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name; + include fastcgi_params; + } + + location ~ /\.ht { + deny all; + } +}