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

97 add docker and GitHub workflow #98

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
.git
.DS_Store
npm-debug.log
19 changes: 19 additions & 0 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build and Push Docker Image

on: # Adjust the triggers, conditions, etc. to your needs, see examples below
pull_request:
push:
branches:
- main
- feat/*
- 97-add-docker-and-github-workflow


jobs:
# You can also build and push multiple images in parallel using a matrix (see examples)
build-and-push-workflow:
uses: ls1intum/.github/.github/workflows/build-and-push-docker-image.yml@main
with:
image-name: ls1intum/apollon2/apollon_reenginerring
docker-file: Dockerfile
secrets: inherit
18 changes: 18 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deploy to Development

on:
workflow_dispatch: # For manual triggers via the GitHub Actions UI
inputs:
image-tag:
type: string
description: "Image tag to deploy (default: pr-<number> if PR exists, latest for default branch)"

jobs:
deploy:
uses: ls1intum/.github/.github/workflows/deploy-docker-compose.yml@main
with:
environment: Production # Replace with your environment
docker-compose-file: "./docker-compose.prod.yml" # Path to your docker-compose file
main-image-name: ls1intum/apollon2
image-tag: ${{ inputs.image-tag }}
secrets: inherit
33 changes: 33 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build and Push Docker Image

on:
push:
branches:
- main # Trigger on pushes to the main branch

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
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@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME_EGE }} #Will be changed later
password: ${{ secrets.DOCKERHUB_PASSWORD_EGE }} #Will be changed later

- name: Build and Push Docker Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: egenerse45/apollon2-webapp:latest, egenerse45/apollon2-webapp:v1.0 #Will be changed later

- name: Logout from Docker Hub
run: docker logout
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Stage 1: Builder
FROM node:20.18.0-slim AS builder

# Create and set working directory
WORKDIR /app

# Copy root-level package and lock files
COPY package*.json ./
# Copy workspace package files (if needed)
COPY library/package*.json ./library/
COPY standalone/webapp/package*.json ./standalone/webapp/
COPY standalone/server/package*.json ./standalone/server/

# Install all dependencies for the entire monorepo using npm ci
RUN npm install

# Copy all source code into the image
COPY . .

# Build the webapp - assuming there's a script at the root or
# you can directly run:
RUN npm run build

# Stage 2: Production image
FROM nginx:alpine
# Remove default nginx pages
RUN rm -rf /usr/share/nginx/html/*

# Copy the built webapp from the builder stage
COPY --from=builder /app/standalone/webapp/dist /usr/share/nginx/html

# Expose port 80
EXPOSE 80

# Default command to run nginx
CMD ["nginx", "-g", "daemon off;"]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ Here are the commonly used scripts defined in the monorepo:
npm run format:check
```

## Dockerized web app

Webapp can be build and run with docker. Be sure docker is installed in your device.

- **Build with docker :**
```bash
npm run docker:build
```
- **Run with docker :**
```bash
npm run docker:start
```
After running 'npm run docker:start' you can navigate to http://localhost:8080/ and start using the application

## Troubleshooting

- If you encounter issues with Node.js versions, ensure you have the correct version installed by running:
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.8'

services:
webapp:
image: "ghcr.io/ls1intum/apollon2/apollon2:${IMAGE_TAG}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we use GitHub container registry, should we keep scripts related to the docker hub? We don't need to also publish to the docker hub I guess.

ports:
- "8080:80"

restart: unless-stopped
Loading
Loading