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

dev: Create a Python package, build Docker images from it #4551

Open
wants to merge 5 commits into
base: mealie-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.idea
.vscode

__pycache__/
**/__pycache__/
*.py[cod]
*$py.class
*.so
Expand All @@ -25,9 +25,11 @@ venv

*/node_modules
*/dist
/dist/
*/data/db
*/mealie/test
*/mealie/.temp
/mealie/frontend/

model.crfmodel

Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ on:
workflow_call:

jobs:
build-package:
name: "Build Python package"
uses: ./.github/workflows/partial-package.yml
with:
tag: e2e

test:
timeout-minutes: 60
needs: build-package
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -18,11 +25,18 @@ jobs:
cache-dependency-path: ./tests/e2e/yarn.lock
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Retrieve Python package
uses: actions/download-artifact@v4
with:
name: backend-dist
path: dist
- name: Build Image
uses: docker/build-push-action@v5
with:
file: ./docker/Dockerfile
context: .
build-contexts: |
packages=dist
push: false
load: true
tags: mealie:e2e
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: ./.github/workflows/partial-backend.yml

frontend-tests:
name: "Frontend and End-to-End Tests"
name: "Frontend Tests"
uses: ./.github/workflows/partial-frontend.yml

build-release:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/partial-backend.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Backend Test/Lint
name: Backend Lint and Test

on:
workflow_call:
Expand Down
19 changes: 15 additions & 4 deletions .github/workflows/partial-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ on:
required: true

jobs:
build-package:
name: "Build Python package"
uses: ./.github/workflows/partial-package.yml
with:
tag: ${{ inputs.tag }}

publish:
needs: build-package
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -35,18 +42,22 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Override __init__.py
run: |
echo "__version__ = \"${{ inputs.tag }}\"" > ./mealie/__init__.py

- uses: depot/setup-action@v1

- name: Retrieve Python package
uses: actions/download-artifact@v4
with:
name: backend-dist
path: dist

- name: Build and push Docker image, via Depot.dev
uses: depot/build-push-action@v1
with:
project: srzjb6mhzm
file: ./docker/Dockerfile
context: .
build-contexts: |
packages=dist
platforms: linux/amd64,linux/arm64
push: true
tags: |
Expand Down
36 changes: 1 addition & 35 deletions .github/workflows/partial-frontend.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Frontend Build/Lin
name: Frontend Lint and Test

on:
workflow_call:
Expand Down Expand Up @@ -41,37 +41,3 @@ jobs:
- name: Run tests 🧪
run: yarn test:ci
working-directory: "frontend"

build:
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎
uses: actions/checkout@v4

- name: Setup node env 🏗
uses: actions/setup-node@v4.0.0
with:
node-version: 16
check-latest: true

- name: Get yarn cache directory path 🛠
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Cache node_modules 📦
uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install dependencies 👨🏻‍💻
run: yarn
working-directory: "frontend"

- name: Run Build 🚚
run: yarn build
working-directory: "frontend"
100 changes: 100 additions & 0 deletions .github/workflows/partial-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Package build

on:
workflow_call:
inputs:
tag:
required: true
type: string

jobs:
build-frontend:
name: Build frontend
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎
uses: actions/checkout@v4

- name: Setup node env 🏗
uses: actions/setup-node@v4.0.0
with:
node-version: 16
check-latest: true

- name: Get yarn cache directory path 🛠
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Cache node_modules 📦
uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install dependencies 👨🏻‍💻
run: yarn
working-directory: "frontend"

- name: Run Build 🚚
run: yarn generate
working-directory: "frontend"

- name: Archive built frontend
uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: frontend/dist
retention-days: 5

build-package:
name: Build Python package
needs: build-frontend
runs-on: ubuntu-latest

steps:
- name: Install Task
uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check out repository
uses: actions/checkout@v4

- name: Set up python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Retrieve built frontend
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: mealie/frontend

- name: Override __init__.py
run: |
echo "__version__ = \"${{ inputs.tag }}\"" > ./mealie/__init__.py

- name: Build package and requirements.txt
env:
SKIP_PACKAGE_DEPS: true
run: |
task py:package

- name: Archive built package
uses: actions/upload-artifact@v4
with:
name: backend-dist
path: dist
retention-days: 5
2 changes: 1 addition & 1 deletion .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: ./.github/workflows/partial-backend.yml

frontend-tests:
name: "Frontend and End-to-End Tests"
name: "Frontend Tests"
uses: ./.github/workflows/partial-frontend.yml

container-scanning:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
uses: ./.github/workflows/partial-backend.yml

frontend-tests:
name: "Frontend and End-to-End Tests"
name: "Frontend Tests"
uses: ./.github/workflows/partial-frontend.yml

build-release:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pnpm-debug.log*
env/
build/
develop-eggs/

/dist/
downloads/
eggs/
.eggs/
Expand All @@ -66,6 +66,9 @@ wheels/
.installed.cfg
*.egg

# frontend copied into Python module for packaging purposes
/mealie/frontend/

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
Loading
Loading