Skip to content

Commit

Permalink
Merge pull request #13 from GiuseppeArbore/OQ-15-CD-Init
Browse files Browse the repository at this point in the history
OQ-15 CD Init
  • Loading branch information
GiuseppeArbore authored Oct 16, 2024
2 parents 629bcdd + 4176073 commit f530e29
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 7 deletions.
56 changes: 53 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: OQ CI
name: CI & CD

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]


env:
# Use docker.io for Docker Hub if empty
REGISTRY: docker.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x, 21.x, 22.x]
node-version: [21.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -42,4 +50,46 @@ jobs:
- run: npm ci
working-directory: ./client
- run: npm run build --if-present
working-directory: ./client
working-directory: ./client
push:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/luca2024poli/polito-se2-24-18-server
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: server
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Extract metadata (tags, labels) for Docker
id: meta_client
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/luca2024poli/polito-se2-24-18-client
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: client
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


11 changes: 11 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:lts-alpine as builder

WORKDIR /app
COPY . ./

RUN npm install && npm run build

FROM nginx:alpine

COPY ./config/nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/dist /usr/share/nginx/html
8 changes: 8 additions & 0 deletions client/config/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}
8 changes: 4 additions & 4 deletions client/package-lock.json

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

21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
services:
client:
build:
context: ./client
ports:
- "80:80"
networks:
- office-q
server:
build:
context: ./server
ports:
- "3001:3001"
volumes:
- ./server/src/db:/app/src/db
networks:
- office-q

networks:
office-q:
driver: bridge
1 change: 1 addition & 0 deletions server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
17 changes: 17 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use the official Node.js image as a base
FROM node:21

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json to the container
COPY . .

RUN npm install


# Expose port 3000 to the outside world
EXPOSE 3001

# Command to run the client application
CMD ["npm", "start"]

0 comments on commit f530e29

Please sign in to comment.