Skip to content

Commit

Permalink
feat(docker): add fullstack docker setup
Browse files Browse the repository at this point in the history
Signed-off-by: Charles Madjeri <[email protected]>
  • Loading branch information
Charles Madjeri committed Dec 5, 2024
1 parent e749213 commit a58dcab
Show file tree
Hide file tree
Showing 21 changed files with 217 additions and 202 deletions.
9 changes: 8 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
VITE_PORT=8081
VITE_PORT=8081

# Server database environment variables
DB_NAME=area
DB_PASSWORD=change-me
DB_HOST=mariadb
DB_PORT=3306
DB_USER=root
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

ssl/
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TARGET_MAX_CHAR_NUM=20

.PHONY: start build stop restart reset logs clean help

PROJECT_IMAGES = area-client-web area-client-mobile
PROJECT_IMAGES = area-client-web area-client-mobile area-server mariadb rabbitmq

## Show help
help:
Expand Down Expand Up @@ -56,4 +56,16 @@ logs:

## Clean up containers, images, volumes and orphans
clean:
docker compose down --rmi local -v --remove-orphans
docker compose down --rmi local -v --remove-orphans

# Flutter mobile client commands
flutter-build:
docker build -t flutter-app ./client_mobile

flutter-run:
docker run -it \
--network host \
-v $(PWD)/client_mobile:/app \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=${DISPLAY} \
flutter-app
36 changes: 13 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ With AREA, you can create automated workflows that integrate various services an
## Table of Contents

- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation & Usage](#installation--usage)
- [Prerequisites](#prerequisites)
- [Installation & Usage](#installation--usage)
- [Documentation](#documentation)
- [Requirements](#requirements)
- [Usage](#usage)
- [Requirements](#requirements)
- [Usage](#usage)
- [Tests](#tests)
- [License](#license)
- [Contributors](#contributors)
Expand All @@ -19,50 +19,39 @@ With AREA, you can create automated workflows that integrate various services an

### Prerequisites

- vite js
- go
- docker
- make

### Installation & Usage

<details>
<summary>Click to expand</summary>

1. Clone the repo

```sh
git clone [email protected]:ASM-Studios/AREA.git
```

2. Create .env files

- Run the following command to create private env files

```sh
cp .env.example .env
cp server/.env.server.example server/.env.server
cp client_web/.env.local.example .env.local
cp client_mobile/.env.mobile.example .env.mobile
```

- Fill the .env, .env.web and .env.mobile files

3. Install NPM packages
```sh
cd AREA/client-web
npm install
```
4. Run the project

3. Install Go packages
```sh
cd AREA/server
<TODO>
make start
```

4. Run the project
```sh
cd AREA/client-web
npm run start
```
```sh
cd AREA/server
go run ./...
```
</details>

### Documentation
Expand All @@ -87,6 +76,7 @@ The documentation is automatically built and deployed to GitHub Pages when a pus
You can consult the documentation online at [AREA Documentation](https://asm-studios.github.io/AREA/).

You can build the documentation locally by running the following command:

```sh
cd AREA/docs
make docs
Expand Down
14 changes: 0 additions & 14 deletions client_mobile/.env.mobile.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
VITE_PORT=8081
VITE_ENDPOINT=http://localhost:8080

VITE_GOOGLE_CLIENT_ID=
VITE_GOOGLE_CLIENT_SECRET=

VITE_MICROSOFT_CLIENT_ID=

VITE_LINKEDIN_CLIENT_ID=
VITE_LINKEDIN_CLIENT_SECRET=

VITE_SPOTIFY_CLIENT_ID=
VITE_SPOTIFY_CLIENT_SECRET=

# Server URLs
API_URL=http://localhost:8080
WEB_CLIENT_URL=http://localhost:8081
Expand Down
28 changes: 12 additions & 16 deletions client_mobile/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
FROM ghcr.io/cirruslabs/flutter:stable
FROM ghcr.io/cirruslabs/flutter:3.24.5 AS builder

WORKDIR /app

ARG VITE_PORT
ARG VITE_ENDPOINT
ARG VITE_GOOGLE_CLIENT_ID
ARG VITE_GOOGLE_CLIENT_SECRET
ARG VITE_MICROSOFT_CLIENT_ID
ARG VITE_LINKEDIN_CLIENT_ID
ARG VITE_LINKEDIN_CLIENT_SECRET
ARG VITE_SPOTIFY_CLIENT_ID
ARG VITE_SPOTIFY_CLIENT_SECRET
RUN git config --system --add safe.directory /sdks/flutter && \
git config --system --add safe.directory /app && \
chmod -R 777 /sdks/flutter

COPY pubspec.* ./

RUN flutter pub get

COPY . .

ARG API_URL
ARG WEB_CLIENT_URL
ARG MOBILE_CLIENT_URL
ARG GITHUB_CLIENT_ID
ARG GITHUB_CLIENT_SECRET

COPY . .

RUN flutter pub get
RUN flutter build apk --release

RUN mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/client.apk
RUN chmod -R 755 build/app/outputs/flutter-apk/
RUN mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/client.apk
2 changes: 1 addition & 1 deletion client_mobile/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: '>=3.4.1 <4.0.0'
sdk: '^3.5.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down
58 changes: 36 additions & 22 deletions client_web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
###----------------------- Certificate generation stage -----------------------###
FROM alpine:3.19 AS cert-builder
FROM alpine:3.20.3 AS cert-builder

# Install mkcert dependencies
RUN apk add --no-cache \
curl \
nss \
nss-tools

# Install mkcert
RUN curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64" \
&& chmod +x mkcert-v*-linux-amd64 \
&& mv mkcert-v*-linux-amd64 /usr/local/bin/mkcert \
&& mkcert -install \
&& mkcert localhost
RUN apk add --no-cache openssl
RUN mkdir -p /etc/nginx/ssl && \
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/nginx/ssl/private.key \
-out /etc/nginx/ssl/certificate.crt \
-subj "/C=FR/ST=Paris/L=Paris/O=Area/OU=IT/CN=localhost" \
-addext "subjectAltName = DNS:localhost" && \
chmod 644 /etc/nginx/ssl/certificate.crt /etc/nginx/ssl/private.key


###----------------------- Build stage for Node.js application -----------------------###
FROM node:latest AS builder
FROM node:20-alpine AS builder

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .

ARG VITE_PORT
ARG VITE_ENDPOINT
ARG VITE_GOOGLE_CLIENT_ID
Expand All @@ -35,20 +36,33 @@ ARG MOBILE_CLIENT_URL
ARG GITHUB_CLIENT_ID
ARG GITHUB_CLIENT_SECRET

COPY ./package*.json ./
RUN npm install
COPY . .

RUN npm run build


###----------------------- Production stage -----------------------###
FROM nginx:alpine AS production
FROM nginx:1.25.3-alpine

COPY --from=builder /app/dist /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
RUN mkdir -p /usr/share/nginx/html/mobile_builds
ARG VITE_PORT

RUN adduser -D nginxuser && \
mkdir -p /usr/share/nginx/html/mobile_builds && \
mkdir -p /etc/nginx/ssl && \
chown -R nginxuser:nginxuser /usr/share/nginx/html && \
chown -R nginxuser:nginxuser /etc/nginx/ssl && \
chown -R nginxuser:nginxuser /var/cache/nginx && \
chown -R nginxuser:nginxuser /var/log/nginx && \
touch /var/run/nginx.pid && \
chown -R nginxuser:nginxuser /var/run/nginx.pid

COPY --from=cert-builder --chown=nginxuser:nginxuser /etc/nginx/ssl /etc/nginx/ssl
COPY --from=builder --chown=nginxuser:nginxuser /app/dist /usr/share/nginx/html
COPY --chown=nginxuser:nginxuser ./nginx.conf /etc/nginx/conf.d/default.conf

USER nginxuser

EXPOSE ${VITE_PORT}

HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:${VITE_PORT}/health || exit 1

CMD ["nginx", "-g", "daemon off;"]
7 changes: 6 additions & 1 deletion client_web/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
server {
listen 8081;
listen 8081 ssl;
server_name localhost;

ssl_certificate /etc/nginx/ssl/certificate.crt;
ssl_certificate_key /etc/nginx/ssl/private.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
Expand Down
5 changes: 0 additions & 5 deletions client_web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import fs from 'fs'
import path from 'path'

export default defineConfig(({ mode }) => {
Expand All @@ -10,10 +9,6 @@ export default defineConfig(({ mode }) => {
plugins: [react()],
server: {
port: parseInt(env.VITE_PORT) || 8081,
https: {
key: fs.readFileSync(path.resolve(__dirname, 'localhost-key.pem')),
cert: fs.readFileSync(path.resolve(__dirname, 'localhost.pem')),
},
},
resolve: {
alias: {
Expand Down
Loading

0 comments on commit a58dcab

Please sign in to comment.