Skip to content

Commit

Permalink
merging 35 improve onboarding experience (#42)
Browse files Browse the repository at this point in the history
See changelog v0.1.0

---------

Co-authored-by: Sebastian Mohr <sebastian@mohrenclan.de>
  • Loading branch information
pSpitzner and semohr authored Nov 13, 2024
1 parent 2584a2e commit 96360da
Show file tree
Hide file tree
Showing 96 changed files with 3,704 additions and 2,514 deletions.
38 changes: 32 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
.conda/
venv/
.venv/
.git
node_modules/
.pnpm-store/
# following this reference suggesting to exclude everything, and only
# manually include whats needed
# https://markbirbeck.com/2018/12/07/getting-control-of-your-dockerignore-files/

# Let's taylor the docker ignore only for the production image, there is no real
# need to push the dev image to the registry

*

!backend/beets_flask
!backend/pyproject.toml
!backend/main.py
!backend/launch_redis_workers.py

!configs/

!frontend/src/
!frontend/public/
!frontend/dist/

!frontend/.eslintrc.js
!frontend/index.html
!frontend/package.json
!frontend/pnpm-lock.yaml
!frontend/postcss.config.js
!frontend/tailwind.config.js
!frontend/tsconfig.json
!frontend/vite.config.ts

!README.md
!LICENSE
!entrypoint*.sh
68 changes: 68 additions & 0 deletions .github/workflows/docker_hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: docker-hub

permissions:
contents: read
packages: write

on:
push:
tags:
- "v*.*.*"
- "test-*"
workflow_dispatch:

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
# generate Docker tags based on the following events/attributes
with:
# list of Docker images to use as base name for tags
images: |
pspitzner/beets-flask
ghcr.io/pspitzner/beets-flask
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=tag
type=semver,pattern={{raw}}
type=sha
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=raw,value=latest,enable=true
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
target: prod
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
30 changes: 30 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Ruff

on:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]

jobs:
ruff:
name: Ruff check and linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
cd ./backend
python -m pip install --upgrade pip
pip install ruff
# Update output format to enable automatic inline annotations.
- name: Run Ruff
run: |
cd ./backend
ruff check --output-format=github .
11 changes: 11 additions & 0 deletions .pre-commit-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.5
hooks:
# Run the linter.
- id: ruff
args: [--fix, --config=./backend/pyproject.toml]
# Run the formatter.
- id: ruff-format
args: [--config=./backend/pyproject.toml]
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Upcoming]
## [0.1.0] - 24-11-13

### Fixed

- Renamed `kind` to `type` in search frontend code to be consistent with backend.
Using kind for tags (preview, import, auto), and types for search (album, track).

### Changed


- Improved readme and onboarding experience
- Mountpoint to persist config files and databases changed to `/config` (was `/home/beetle/.config/beets/`)
We create the `/config/beets` and `/config/beets-flask` folders on startup if they do not exist.
Library files are placed there, and you can drop a `config.yaml` either or both of these folders. Settings in `/config/beets-flask/config.yaml` take precedence over `/config/beets/config.yaml`.
**You will need to update your docker-compose!**

### Added

- Logo and favicon
- Image now on docker hub: `pspitzner/beets-flask:stable`
- Auto-import: automatically import folders that are added to the inbox if the match is good enough.
After a preview, import will start if the match quality is above the configured.
Enable via the config.yaml, set the `autotag` field of a configred inbox folders to `"auto"`.
Expand Down Expand Up @@ -67,6 +78,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- initial commit

[0.1.0]: https://github.com/pSpitzner/beets-flask/compare/v0.0.4...v0.1.0
[0.0.4]: https://github.com/pSpitzner/beets-flask/compare/v0.0.3...v0.0.4
[0.0.3]: https://github.com/pSpitzner/beets-flask/compare/v0.0.2...v0.0.3
[0.0.2]: https://github.com/pSpitzner/beets-flask/compare/v0.0.1...v0.0.2
98 changes: 60 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,58 @@ FROM python:3.11-alpine AS base

FROM base AS deps

ARG USER_ID
ARG GROUP_ID
ENV USER_ID=$USER_ID
ENV GROUP_ID=$GROUP_ID
RUN addgroup -g $GROUP_ID beetle && adduser -D -u $USER_ID -G beetle beetle
RUN addgroup -g 1000 beetle && \
adduser -D -u 1000 -G beetle beetle

# dependencies
WORKDIR /repo
COPY requirements.txt .
RUN --mount=type=cache,target=/var/cache/apk \
apk --no-cache update
RUN --mount=type=cache,target=/var/cache/apk \
apk --no-cache add imagemagick redis git bash keyfinder-cli npm tmux yq
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install -r requirements.txt
RUN corepack enable && corepack prepare pnpm@9.4.0 --activate
ENV HOSTNAME="beets-container"

# map beets directory and our configs to /config
RUN mkdir -p /config/beets
RUN mkdir -p /config/beets-flask
RUN chown -R beetle:beetle /config
ENV BEETSDIR="/config/beets"
ENV BEETSFLASKDIR="/config/beets-flask"

# our default folders they should not be used in production
RUN mkdir -p /music/inbox
RUN mkdir -p /music/imported
RUN chown -R beetle:beetle /music

# dependencies
RUN --mount=type=cache,target=/var/cache/apk \
apk update
RUN --mount=type=cache,target=/var/cache/apk \
apk add \
imagemagick \
redis \
git \
bash \
keyfinder-cli \
npm \
tmux \
shadow

# Install our package (backend)
COPY ./backend /repo/backend
COPY ./README.md /repo/README.md
WORKDIR /repo/backend
RUN --mount=type=cache,target=/root/.cache/pip \
pip install .

# Install frontend
RUN corepack enable && corepack prepare pnpm@9.x.x --activate

# ------------------------------------------------------------------------------------ #
# Development #
# ------------------------------------------------------------------------------------ #

FROM deps AS dev

WORKDIR /repo
COPY --from=deps /repo /repo
COPY entrypoint_dev.sh .
RUN chown -R beetle:beetle /repo
RUN chmod +x ./entrypoint_dev.sh
ENV IB_SERVER_CONFIG="dev_docker"

# we copy config files in the script, so they can be put into mounted volumes
# relies on mounting this volume
WORKDIR /repo
USER beetle

USER root
ENTRYPOINT ["./entrypoint_dev.sh"]

# ------------------------------------------------------------------------------------ #
Expand All @@ -49,34 +63,42 @@ ENTRYPOINT ["./entrypoint_dev.sh"]
FROM deps AS test

WORKDIR /repo
COPY --from=deps /repo /repo
COPY --from=deps --chown=beetle:beetle /repo /repo
COPY entrypoint_test.sh .
RUN mkdir -p /music/inbox
RUN chown -R beetle:beetle /music/inbox
RUN chown -R beetle:beetle /repo
RUN chmod +x ./entrypoint_test.sh
USER beetle
ENV IB_SERVER_CONFIG="test"
USER root
ENTRYPOINT ["./entrypoint_test.sh"]

# ------------------------------------------------------------------------------------ #
# Production #
# ------------------------------------------------------------------------------------ #

FROM deps AS prod
FROM deps AS build

WORKDIR /repo
COPY --from=deps /repo /repo
COPY --chown=beetle:beetle . .
RUN chmod +x ./entrypoint.sh

WORKDIR /repo
COPY ./frontend ./frontend/
RUN chown -R beetle:beetle /repo

USER beetle
WORKDIR /repo/frontend
RUN rm -rf node_modules
RUN rm -rf dist
RUN rm -rf .pnpm-store
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
pnpm install
RUN pnpm run build

# ------------------------------------------------------------------------------------ #

FROM deps AS prod

ENV IB_SERVER_CONFIG="prod"

WORKDIR /repo
USER beetle
ENTRYPOINT ["./entrypoint.sh"]
COPY --from=deps /repo /repo
COPY --from=build /repo/frontend/dist /repo/frontend/dist
COPY entrypoint.sh .
COPY entrypoint_fix_permissions.sh .
RUN chown -R beetle:beetle /repo

USER root
ENTRYPOINT ["/bin/sh", "-c", "./entrypoint_fix_permissions.sh && su beetle -c ./entrypoint.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2024 F. Paul Spitzner, Sebastian B. Mohr

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Loading

0 comments on commit 96360da

Please sign in to comment.