Skip to content

Commit

Permalink
Implement containerisation and automatic image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Bravewave committed Nov 17, 2024
1 parent 5cbf73d commit 9fcec0f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 3 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build and Push Container Images

on:
push:
branches:
- containers
pull_request:
branches:
- containers

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 22.8.0

- name: Install dependencies and build frontend
run: |
cd frontend
npm ci
npm run build
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN}}

# 4. Build and push Frontend Docker image to GHCR
- name: Build Frontend Docker image
run: |
docker build -t ghcr.io/${{ github.repository }}/frontend:latest ./frontend
docker push ghcr.io/${{ github.repository }}/frontend:latest
# 5. Build and push Backend Docker image to GHCR
- name: Build Backend Docker image
run: |
docker build -t ghcr.io/${{ github.repository }}/backend:latest ./backend
docker push ghcr.io/${{ github.repository }}/backend:latest
13 changes: 13 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20-alpine

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm i --omit=dev

COPY . .

EXPOSE 3000

CMD ["npm", "run", "start"]
1 change: 0 additions & 1 deletion backend/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require('dotenv').config()
const express = require('express');
const mongoose = require('mongoose');
const {auth} = require('express-openid-connect');
Expand Down
3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.0.0",
"main": "app.js",
"scripts": {
"dev": "nodemon --env-file=cfg/.env app.js"
"dev": "nodemon --env-file=cfg/.env app.js",
"start": "node --env-file=cfg/.env app.js"
},
"author": "",
"license": "ISC",
Expand Down
Empty file added docker-compose.yml
Empty file.
7 changes: 7 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM httpd:alpine

WORKDIR /usr/src/app

COPY ./dist /usr/local/apache2/htdocs/

EXPOSE 5173
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
},
Expand Down

0 comments on commit 9fcec0f

Please sign in to comment.