Skip to content

Commit

Permalink
feat: infra ec2 github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
aseerkt committed Aug 9, 2024
1 parent 46105c3 commit 4f4067d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/cd.yml → .github/workflows/ec2-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
runs-on: self-hosted
runs-on: ubuntu-latest

steps:
- name: Checkout
Expand All @@ -33,9 +33,30 @@ jobs:
- name: Build packages
run: pnpm build

- name: Upload build files
uses: actions/upload-artifact@v4
with:
name: mchat_build
path: |
server
web/dist
infra/ec2
deploy:
runs-on: self-hosted
needs: build
steps:
- name: Download math result for job 1
uses: actions/download-artifact@v4
with:
name: mchat_build

- name: Move static files
run: mv web/dist /var/www/html

- name: Restart application
run: pm2 restart mchat




5 changes: 5 additions & 0 deletions infra/ec2/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mchat.aseerkt.com {
encode zstd gzip
file_server
reverse_proxy /api/* 127.0.0.1:5000
}
File renamed without changes.
20 changes: 20 additions & 0 deletions docker-compose.prod.yml → infra/ec2/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ 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:
- $PWD/Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config

volumes:
caddy_data:
external: true
caddy_config:
33 changes: 33 additions & 0 deletions infra/ec2/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# INSTALL NODE.JS

# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# download and install Node.js (you may need to restart the terminal)
nvm install 20

# verifies the right Node.js version is in the environment
node -v # should print `v20.16.0`

# verifies the right npm version is in the environment
npm -v # should print `10.8.1`

npm i -g pm2

# INSTALL DOCKER

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" |
sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

0 comments on commit 4f4067d

Please sign in to comment.