Skip to content

Commit

Permalink
Merge pull request #5 from Randers-Kommune-Digitalisering/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
st-randers authored Oct 28, 2024
2 parents 7f8e3bb + 6e4ae19 commit 6432fdd
Show file tree
Hide file tree
Showing 59 changed files with 2,445 additions and 12,329 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flask/__pycache__/
flask/src/__pycache__/
vue/node_modules/
10 changes: 6 additions & 4 deletions .github/workflows/build-auto.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# This is a basic workflow to help you get started with Actions

name: CI
name: Build (auto)

# Controls when the workflow will run
on:
push:
branches: [ main ]
tags:
- 'v*.*.*'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
workflow_run:
workflows: [Test]
branches: [develop, main]
types:
- completed

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/lint.yaml → .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: Test

# Controls when the workflow will run
on:
Expand Down Expand Up @@ -28,11 +28,14 @@ jobs:
sudo apt-get update -y
sudo apt-get install -y libmariadb-dev
python -m pip install --upgrade pip
pip install -r python/src/requirements.txt
pip install -r requirements-dev.txt
pip install -r flask/src/requirements.txt
pip install -r flask/requirements-dev.txt
- name: Check for syntax errors or undefined names
run: |
flake8 python/src tests --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 flask/src flask/tests --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Unit tests with pytest
run: |
pytest
- name: Lint with flake8
run: |
flake8 --ignore=E501,W293 python/src tests --show-source
flake8 --ignore=E501,W293 flask/src flask/tests --show-source
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ coverage
*.njsproj
*.sln
*.sw?
.env*
.env*

# virtualenv
.venv
48 changes: 31 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
FROM node:14-alpine AS frontend
FROM node:23-alpine AS vue-build

WORKDIR /app

COPY vue/package*.json ./vue/
RUN cd vue && npm install
## Build and copy the vue app
COPY vue .
RUN npm install && npm run build

COPY vue/ ./vue/
RUN cd vue && npm run build
FROM python:3.12-alpine

RUN cp -r vue/dist dist
# Set dir and user
ENV GROUP_NAME=app
ENV HOME=/app
ENV GROUP_ID=11000
ENV USER_ID=11001
ENV PORT=8080

RUN rm -rf vue

FROM python:3.10-alpine AS backend

WORKDIR /app
# Add user
RUN addgroup --gid $GROUP_ID $GROUP_NAME && \
adduser $USER_ID -u $USER_ID -D -G $GROUP_NAME -h $HOME

# Install packages
RUN apk update
RUN apk add musl-dev gcc libpq-dev mariadb-connector-c-dev postgresql-dev python3-dev

COPY python/src/requirements.txt ./python/src/
RUN pip install -r python/src/requirements.txt
# Set working dir
WORKDIR $HOME

# Copy files and
COPY --from=vue-build /app/dist ./dist
COPY flask/src .

# Install python packages
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

COPY python/ ./python/
# Open port
EXPOSE $PORT

COPY --from=frontend /app/dist /app/frontend
# Set user
USER $USER_ID

EXPOSE 8000
CMD ["python", "python/src/main.py"]
ENTRYPOINT ["python"]
CMD ["main.py"]
29 changes: 29 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM node:20-alpine

ENV HOME=/app
ENV FLASK_PORT=8080
ENV VITE_PORT=3000

RUN apk add python3 py3-pip musl-dev gcc libpq-dev mariadb-connector-c-dev postgresql-dev python3-dev

WORKDIR $HOME/vue

COPY ./vue/package*.json ./

RUN cd $HOME/vue && npm install

COPY ./vue $HOME/vue

WORKDIR $HOME/flask

COPY ./flask/src $HOME/flask

RUN pip install --upgrade pip --break-system-packages

RUN pip install -r requirements.txt --break-system-packages

EXPOSE $FLASK_PORT $VITE_PORT

# EXPOSE $VITE_PORT
# ENTRYPOINT ["sh", "-c", "cd /app/vue && npm run host"]
ENTRYPOINT ["sh", "-c", "cd /app/flask && python main.py & cd /app/vue && npm run host"]
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Vue-Python-Tempplate
Template for vue and python projects
Template for vue and python projects.
NB: backend endpoints er åbne udtil (samme som frontend'en). Hvis der skal bruges en "rigtig" backend - deploy [vue](https://github.com/Randers-Kommune-Digitalisering/vue-js-template) og [flask](https://github.com/Randers-Kommune-Digitalisering/python-app-template) i hver sin pod.

## Kørsel af frontend + backend i docker
* Kør ```docker-compose up``` i top dir
* Backend på port 8080, frontend på port 3000

## Kørsel af Frontenden(Vue)
* CD hen til vue folder: ``` cd vue ```
* Installerer afhængigheder: ``` npm install ```
* Compile, hot reload og start frontenden: ``` npm run serve ```
* Compile, hot reload og start frontenden: ``` npm run dev ```

## Kørsel af Bakcenden(Python)
* CD hen til python folder: ``` cd python\src ```
* Start applikationen: ``` python main.py ```

* Start applikationen: ``` python flask/src/main.py ```

## Udviklings commands:
* Bygge docker image: ```docker build -t vue-python-template .```
Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
app:
build:
context: .
dockerfile: Dockerfile.dev

ports:
- "8080:8080"
- "3000:3000"
environment:
DEBUG: True
CHOKIDAR_USEPOLLING: true
volumes:
- ./vue:/app/vue:delegated
- /app/vue/node_modules
- ./flask/src/:/app/flask/
# - "./vue/:/app/vue/"
command: sh -c "cd /app/flask && python main.py & cd /app/vue && npm run host"
File renamed without changes.
11 changes: 11 additions & 0 deletions flask/src/api_endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import logging

from flask import Blueprint, jsonify

logger = logging.getLogger(__name__)
api_endpoints = Blueprint('api', __name__, url_prefix='/api')


@api_endpoints.route('/status', methods=['GET'])
def status():
return jsonify({"success": True, "message": "API is up and running"})
18 changes: 14 additions & 4 deletions python/src/main.py → flask/src/main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from flask import Flask
import os
from flask import Flask, send_from_directory
from healthcheck import HealthCheck
from prometheus_client import generate_latest
from utils.logging import set_logging_configuration, is_ready_gauge, last_updated_gauge
from utils.config import DEBUG, PORT, POD_NAME
from api_endpoints import api_endpoints # Uncomment to import enpoints
from api_endpoints import api_endpoints

set_logging_configuration()


def create_app():
app = Flask(__name__)
app = Flask(__name__, static_folder='dist', static_url_path='/')
health = HealthCheck()
app.add_url_rule('/healthz', 'healthcheck', view_func=lambda: health.run())
app.add_url_rule('/metrics', 'metrics', view_func=generate_latest)

app.register_blueprint(api_endpoints) # Uncomment to add enpoints from api_endpoints.py
app.register_blueprint(api_endpoints)

@app.before_request
def set_ready():
Expand All @@ -27,5 +28,14 @@ def set_ready():
app = create_app()


@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def serve(path):
if path != "" and os.path.exists(app.static_folder + '/' + path):
return send_from_directory(app.static_folder, path)
else:
return send_from_directory(app.static_folder, 'index.html')


if __name__ == '__main__': # pragma: no cover
app.run(debug=DEBUG, host='0.0.0.0', port=PORT)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[pytest]
minversion = 7.0
addopts = --cov=flask/src --cov-report term-missing
pythonpath = flask/src
testpaths = flask/tests
env =
DEBUG=False
POD_NAME=test-pod
33 changes: 0 additions & 33 deletions python/src/Dockerfile

This file was deleted.

56 changes: 0 additions & 56 deletions python/src/api_endpoints.py

This file was deleted.

28 changes: 28 additions & 0 deletions vue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
Loading

0 comments on commit 6432fdd

Please sign in to comment.