Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update actions with db #16

Merged
merged 6 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/cd-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CD-DEV

on:
workflow_run:
workflows: ["CI"]
types:
- completed

jobs:
deploy:
name: Deploy
if: github.event.workflow_run.head_branch == 'develop'
runs-on: ubuntu-latest
environment: Development
steps:
- uses: actions/checkout@v4

- name: Docker login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build image
run: |
cd ./server
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ vars.IMAGE_NAME }}:latest .

- name: Push image
run: |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ vars.IMAGE_NAME }}:latest

- name: Setup ssh
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa

- name: SCP core files
run: |
scp -r docker-compose.yml nginx.conf db-scripts/ .env ${{ vars.SERVER_USER }}@${{ vars.SERVER_IP }}

- name: SSH into server
run: |
ssh -o StrictHostKeyChecking=no ${{ vars.SERVER_USER }}@${{ vars.SERVER_IP }}
docker compose down
docker compose up --build -d
109 changes: 63 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,93 @@ name: CI

on:
push:
branches:
- "**" # currently run on all branches
pull_request:
types: [opened, synchronize, reopened]

jobs:
test:
typecheck:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- uses: ./.github/actions/setup
with:
os: ${{ runner.os }}

- uses: ./.github/actions/setup
with:
os: ${{ runner.os }}

- name: Run tests
run: |
cd server
bun test
- name: Run typecheck
run: |
cd server
bun run typecheck

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- uses: ./.github/actions/setup
with:
os: ${{ runner.os }}
- uses: ./.github/actions/setup
with:
os: ${{ runner.os }}

- name: Lint fix
run: |
cd server/
bun lint --fix
- name: Lint fix
run: |
cd server/
bun lint --fix

- name: Commit lint fix
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
if ! git diff --exit-code > /dev/null
then
git commit -a -m "lint fix"
git push
fi
- name: Commit lint fix
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
if ! git diff --exit-code > /dev/null
then
git commit -a -m "lint fix"
git push
fi

- name: Run linter
run: |
cd server
bun run lint
- name: Run linter
run: |
cd server
bun run lint

typecheck:
test:
runs-on: ubuntu-latest
services:
db:
image: postgres:latest
ports:
- 5432:5432
volumes:
- ./db-scripts:/docker-entrypoint-initdb.d/
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: acm_website
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s
--health-timeout 5s
--health-retries 5
--health-start-period 15s
steps:
- uses: actions/checkout@v4

- uses: actions/checkout@v4
- uses: ./.github/actions/setup
with:
os: ${{ runner.os }}

- name: Run typecheck
- name: Run tests
run: |
cd server
bun run typecheck
bun test

pr-check:
if: github.event_name == 'pull_request'
needs: [test, lint, typecheck]
build:
needs: [typecheck, lint, test]
runs-on: ubuntu-latest
steps:
- name: PR is ready to be merged
run: echo "All checks passed. PR is ready to be merged."
- uses: actions/checkout@v4

- name: Build
run: |
cd ./server
docker build --target=run --no-cache .

23 changes: 4 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
nginx:
image: nginx:latest
ports:
- 8080:8080
- 80:80
configs:
- source: nginx_config
target: /etc/nginx/nginx.conf
Expand All @@ -14,12 +14,7 @@ services:
restart: true

server:
build:
context: ./server
dockerfile: Dockerfile.dev
volumes:
- ./server:/app
- /app/node_modules
image: manasc478/acm-website-server:latest
environment:
- NODE_ENV=development
env_file:
Expand All @@ -40,17 +35,11 @@ services:

db:
image: postgres:latest
# ports:
# - "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_DB: acm_website
POSTGRES_PASSWORD_FILE: /run/secrets/pg_password
volumes:
- acm_website_db_data:/var/lib/postgresql/data
- ./db-scripts:/docker-entrypoint-initdb.d/
secrets:
- pg_password
env_file:
- .env
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 5s
Expand All @@ -74,7 +63,3 @@ networks:
configs:
nginx_config:
file: ./nginx.conf

secrets:
pg_password:
file: ./pg_password.txt
9 changes: 7 additions & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ http {
}

server {
listen 8080;

listen 80;
server_name acm-website-server.crabdance.com;

location / {
proxy_pass http://app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
13 changes: 13 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM oven/bun:alpine as base
RUN apk --no-cache add curl
WORKDIR /app

FROM base as install
COPY package.json bun.lockb ./
RUN bun install

FROM install as run
COPY ./server /app
EXPOSE 5001
CMD ["bun", "run", "dev"]

Loading