diff --git a/.github/workflows/ec2-cd.yml b/.github/workflows/ec2-cd.yml index 42265c0..850e4b1 100644 --- a/.github/workflows/ec2-cd.yml +++ b/.github/workflows/ec2-cd.yml @@ -31,6 +31,8 @@ jobs: run: pnpm i - name: Build packages + env: + VITE_BACKEND_URL: https://${{ secrets.APP_DOMAIN }} run: pnpm build - name: Upload build files @@ -53,8 +55,19 @@ jobs: name: mchat_build - name: Move static files - run: sudo mv web/dist /var/www/html + run: | + sudo rm -rf /var/www/html/* + sudo mv web/dist/* /var/www/html/ + sudo rm -rf web/dist + - name: Reload caddy service + run: | + sudo systemctl reload caddy + + # - name: Set server env file + # run: + # cd server && cp .env.example .env + - name: Restart application run: pm2 restart mchat diff --git a/infra/ec2/Caddyfile b/infra/ec2/Caddyfile index d41f505..497e85e 100644 --- a/infra/ec2/Caddyfile +++ b/infra/ec2/Caddyfile @@ -1,5 +1,6 @@ mchat.aseerkt.com { + root * /var/www/html encode zstd gzip - file_server /dist/* + file_server reverse_proxy /api/* 127.0.0.1:5000 } diff --git a/infra/ec2/Makefile b/infra/ec2/Makefile deleted file mode 100644 index de15541..0000000 --- a/infra/ec2/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -deploydb: - sudo docker compose -f docker-compose.prod.yml up -d - -destroydb: - sudo docker compose -f docker-compose.prod.yml down \ No newline at end of file diff --git a/infra/ec2/docker-compose.prod.yml b/infra/ec2/docker-compose.prod.yml index f32299e..d415b07 100644 --- a/infra/ec2/docker-compose.prod.yml +++ b/infra/ec2/docker-compose.prod.yml @@ -23,16 +23,3 @@ services: interval: 30s timeout: 10s retries: 5 - - caddy: - image: caddy:2.8.4-alpine - container_name: mchat_caddy - restart: unless-stopped - cap_add: - - NET_ADMIN - ports: - - '80:80' - - '443:443' - - '443:443/udp' - volumes: - - ./Caddyfile:/etc/caddy/Caddyfile diff --git a/infra/ec2/docker-down.sh b/infra/ec2/docker-down.sh new file mode 100644 index 0000000..ce0645d --- /dev/null +++ b/infra/ec2/docker-down.sh @@ -0,0 +1 @@ +sudo docker compose -f docker-compose.prod.yml down diff --git a/infra/ec2/docker-up.sh b/infra/ec2/docker-up.sh new file mode 100644 index 0000000..2fb8766 --- /dev/null +++ b/infra/ec2/docker-up.sh @@ -0,0 +1 @@ +sudo docker compose -f docker-compose.prod.yml up -d diff --git a/infra/ec2/install.sh b/infra/ec2/init.sh similarity index 66% rename from infra/ec2/install.sh rename to infra/ec2/init.sh index 442f7ea..afe1f82 100644 --- a/infra/ec2/install.sh +++ b/infra/ec2/init.sh @@ -1,4 +1,4 @@ -# INSTALL NODE.JS +## INSTALL NODE.JS # installs nvm (Node Version Manager) curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash @@ -12,9 +12,11 @@ node -v # should print `v20.16.0` # verifies the right npm version is in the environment npm -v # should print `10.8.1` +## INSTALL PM2 + npm i -g pm2 -# INSTALL DOCKER +## INSTALL DOCKER # Add Docker's official GPG key: sudo apt-get update @@ -31,3 +33,19 @@ echo \ sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + +## INSTAL CADDY + +sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl +curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg +curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list +sudo apt update +sudo apt install caddy + +sudo mkdir /srv + +cp ./Caddyfile /etc/caddy/Caddyfile + +./reload-caddy.sh + +./docker-up.sh diff --git a/infra/ec2/reload-caddy.sh b/infra/ec2/reload-caddy.sh new file mode 100644 index 0000000..4fc2671 --- /dev/null +++ b/infra/ec2/reload-caddy.sh @@ -0,0 +1 @@ +sudo systemctl reload caddy