Skip to content

Commit

Permalink
Merge pull request #32 from sybila/ci-experiments
Browse files Browse the repository at this point in the history
Ci experiments
  • Loading branch information
daemontus authored Nov 16, 2023
2 parents 2cbd045 + 91005aa commit 72f7525
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 1 deletion.
87 changes: 87 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Generate Docker Containers

on:
push:
tags:
- '*'

jobs:
database:
name: Build backend database
runs-on: ubuntu-latest
env:
DATABASE_URL: "postgresql://postgres:postgres@localhost:5555/postgres"
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Start database
working-directory: backend
run: |
docker run -d \
--name my-db \
-p 5555:5432 \
-e PGDATA=/data \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres \
postgres:16
- name: Init DB with prisma
working-directory: backend
run: npx prisma migrate dev --name init
- name: Seed DB with data
working-directory: backend
run: npm run seed
- name: Commit current state of the container
working-directory: backend
run: docker commit my-db daemontus/bbm-database:latest
- name: Push image
working-directory: backend
run: docker push daemontus/bbm-database

backend:
name: Build backend image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image
working-directory: backend
run: docker build -t daemontus/bbm-backend .
- name: Push image
working-directory: backend
run: docker push daemontus/bbm-backend

frontend:
name: Build frontend image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Add Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
- name: Install dependencies
working-directory: frontend
run: npm install
- name: Build frontend
working-directory: frontend
run: npm run build
- name: Build image
working-directory: frontend
run: docker build -t daemontus/bbm-frontend .
- name: Push image
working-directory: frontend
run: docker push daemontus/bbm-frontend
15 changes: 15 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Container is based on Alpine linux with node.js preinstalled.
FROM node:alpine
WORKDIR /usr/mynodeapp

# Copy backend files.
COPY ./ ./

# Install project dependencies.
RUN npm install

# The port on which the backend is running.
EXPOSE 3000

# Run server.
CMD ["npm", "start"]
61 changes: 61 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"morgan": "^1.10.0",
"zod": "^3.22.2"
},
"devDependencies": {
"@types/cors": "^2.8.14",
"@types/express": "^4.17.17",
"@types/morgan": "^1.9.9",
"@types/node": "^20.6.3",
"prisma": "^5.3.1",
"ts-node": "^10.9.1",
Expand Down
4 changes: 4 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ApiResponse } from './types';
import modelRouter from "./routes/modelRoutes";
import bodyParser from "body-parser";
import webhookRouter from "./routes/webhookRoutes";
import morgan from 'morgan';

const app = express();
const port = env.PORT ?? 3000;
Expand All @@ -14,6 +15,9 @@ app.use(bodyParser.json());
// CORS middleware
app.use(cors());

// Logging
app.use(morgan('combined'))

// My implemented routers
app.use(modelRouter);
app.use(webhookRouter);
Expand Down
8 changes: 8 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM nginx:1.24.0

COPY nginx.conf /etc/nginx/nginx.conf
COPY ./dist /www
COPY startup.sh .
RUN chmod +x ./startup.sh

CMD /bin/bash -c "./startup.sh"
16 changes: 16 additions & 0 deletions frontend/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
events {
# configuration of connection processing
}

http {
server {
listen 80;
server_name bbm.unsigned-short.com;

root /www;

location / {
include /etc/nginx/mime.types;
}
}
}
2 changes: 1 addition & 1 deletion frontend/src/services/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";

const axiosInstance = axios.create({
baseURL: 'http://localhost:3001',
baseURL: '${BACKEND_URL}',
});

export default axiosInstance;
15 changes: 15 additions & 0 deletions frontend/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

folder_path="/www/assets"

file_path=$(find "$folder_path" -type f -name "*.js" -print -quit)

if [ -n "$file_path" ]; then
envsubst '${BACKEND_URL}' < "$file_path" > tmp.js
mv tmp.js "$file_path"
echo "URL substituted."
else
echo "No JavaScript file found."
fi

nginx -g 'daemon off;'

0 comments on commit 72f7525

Please sign in to comment.