Skip to content

Commit

Permalink
Merge branch 'main' into webapp
Browse files Browse the repository at this point in the history
  • Loading branch information
doubaniux committed Oct 29, 2023
2 parents 1006533 + c872af7 commit 2cbca22
Show file tree
Hide file tree
Showing 199 changed files with 8,726 additions and 2,010 deletions.
20 changes: 20 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.DS_Store
.env
.venv
.vscode
.github
.gitignore
.pre-commit-config.yaml
__pycache__
/compose.yml
/compose.override.yml
/Dockerfile
/doc
/media
/static
/test_data
/neodb
/neodb-takahe/doc
/neodb-takahe/docker
/neodb-takahe/static-collected
/neodb-takahe/takahe/local_settings.py
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml → .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: check
name: code check

on: [push, pull_request]

Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
name: Deployment
name: preview deployment
on:
workflow_run:
workflows: ["all tests"]
branches: [main]
workflows: ["docker image"]
types:
- completed
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
deployment:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
name: Deployment
name: deployment to preview environment
runs-on: ubuntu-latest
environment: preview
environment: ${{ vars.DEPLOY_ENV }}
steps:
- name: ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: ${{ vars.DEPLOY_SCRIPT }}
44 changes: 0 additions & 44 deletions .github/workflows/django.yml

This file was deleted.

54 changes: 54 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: docker image

on:
workflow_run:
workflows: ["unit test"]
branches:
- main
- activitypub
types:
- completed

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build_and_push_image:
name: build image and push to Docker Hub
if: ${{ github.event.workflow_run.conclusion == 'success' }}
# if: github.repository_owner == 'neodb-social'
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
with:
submodules: 'true'

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

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

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: neodb/neodb

- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: "linux/amd64,linux/arm64"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
55 changes: 55 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: unit test

on:
push:
pull_request:
branches: [ "main" ]

jobs:
django:
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- 6379:6379
db:
image: postgres
env:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
POSTGRES_DB: test_neodb
ports:
- 5432:5432
db2:
image: postgres
env:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
POSTGRES_DB: test_neodb_takahe
ports:
- 15432:5432
strategy:
max-parallel: 4
matrix:
python-version: ['3.11']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install Dependencies
run: |
pip install -r requirements.txt
- name: Run Tests
env:
NEODB_DB_URL: postgres://testuser:[email protected]/test_neodb
TAKAHE_DB_URL: postgres://testuser:[email protected]/test_neodb_takahe
NEODB_REDIS_URL: redis://127.0.0.1:6379/0
NEODB_SITE_NAME: test
NEODB_SITE_DOMAIN: test.domain
NEODB_SECRET_KEY: test
run: |
python manage.py test
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = webapp
url = https://github.com/neodb-social/webapp.git
branch = main
[submodule "neodb-takahe"]
path = neodb-takahe
url = https://github.com/neodb-social/neodb-takahe.git
branch = neodb
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ repos:
rev: 22.12.0
hooks:
- id: black
language_version: python3.11

- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.32.1
Expand Down
75 changes: 51 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,58 @@
# syntax=docker/dockerfile:1
FROM python:3.11-slim-bullseye
FROM python:3.11-slim as build
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN --mount=type=cache,sharing=locked,target=/var/cache/apt apt-get update \
&& apt-get install -y --no-install-recommends build-essential libpq-dev python3-venv git

COPY . /neodb

RUN echo neodb-`cd /neodb && git rev-parse --short HEAD`-`cd /neodb/neodb-takahe && git rev-parse --short HEAD`-`date -u +%Y%m%d%H%M%S` > /neodb/version
RUN rm -rf /neodb/.git /neodb/neodb-takahe/.git

RUN mv /neodb/neodb-takahe /takahe

WORKDIR /neodb
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
RUN python -m venv /neodb-venv
RUN --mount=type=cache,sharing=locked,target=/root/.cache /neodb-venv/bin/python3 -m pip install --upgrade -r requirements.txt

WORKDIR /takahe
RUN python -m venv /takahe-venv
RUN --mount=type=cache,sharing=locked,target=/root/.cache /takahe-venv/bin/python3 -m pip install --upgrade -r requirements.txt

# runtime stage
FROM python:3.11-slim as runtime
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN --mount=type=cache,sharing=locked,target=/var/cache/apt-run apt-get update \
&& apt-get install -y --no-install-recommends libpq-dev \
busybox \
postgresql-client \
nginx \
opencc \
git
COPY misc/nginx.conf.d/* /etc/nginx/conf.d/
RUN echo >> /etc/nginx/nginx.conf
RUN echo 'daemon off;' >> /etc/nginx/nginx.conf
RUN python3 -m pip install --no-cache-dir --upgrade -r requirements.txt
RUN apt-get purge -y --auto-remove \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*

RUN python3 manage.py compilescss \
&& python3 manage.py collectstatic --noinput
RUN cp -R misc/www /www
RUN mv static /www/static

# invoke check by default
CMD [ "python3", "/neodb/manage.py", "check" ]
gettext-base
RUN busybox --install

# postgresql and redis cli are not required, but install for development convenience
RUN --mount=type=cache,sharing=locked,target=/var/cache/apt-run apt-get install -y --no-install-recommends postgresql-client redis-tools
RUN useradd -U app
RUN rm -rf /var/lib/apt/lists/*

COPY --from=build /neodb /neodb
WORKDIR /neodb
COPY --from=build /neodb-venv /neodb-venv
RUN NEODB_SECRET_KEY="t" NEODB_SITE_DOMAIN="x.y" NEODB_SITE_NAME="z" /neodb-venv/bin/python3 manage.py compilescss
RUN NEODB_SECRET_KEY="t" NEODB_SITE_DOMAIN="x.y" NEODB_SITE_NAME="z" /neodb-venv/bin/python3 manage.py collectstatic --noinput

COPY --from=build /takahe /takahe
WORKDIR /takahe
COPY --from=build /takahe-venv /takahe-venv
RUN TAKAHE_DATABASE_SERVER="postgres://x@y/z" TAKAHE_SECRET_KEY="t" TAKAHE_MAIN_DOMAIN="x.y" /takahe-venv/bin/python3 manage.py collectstatic --noinput

WORKDIR /neodb
COPY misc/bin/* /bin/
RUN mkdir -p /www

USER app:app

CMD [ "neodb-hello"]
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Boofilsic/NeoDB

![Test Status](https://github.com/neodb-social/neodb/actions/workflows/django.yml/badge.svg?branch=main)
![](https://github.com/neodb-social/neodb/actions/workflows/check.yml/badge.svg?branch=main)
![](https://github.com/neodb-social/neodb/actions/workflows/tests.yml/badge.svg?branch=main)
![](https://github.com/neodb-social/neodb/actions/workflows/publish.yml/badge.svg?branch=main)

Boofilsic/NeoDB is an open source project and free service to help users manage, share and discover collections, reviews and ratings for culture products (e.g. books, movies, music, podcasts, games and performances) in Fediverse.

Expand Down Expand Up @@ -41,7 +43,7 @@ Boofilsic/NeoDB is an open source project and free service to help users manage,
* eligible items, e.g. podcasts and albums, are playable in feed
+ link Fediverse account and import social graph
+ share collections and reviews to Fediverse ~~and Twitter~~ feed
+ ActivityPub support is under development, a pre-alpha version is available for developers as [docker image](https://hub.docker.com/r/neodb/neodb)
+ ActivityPub support is under active development
- Other
+ i18n/language support are planned

Expand Down
Loading

0 comments on commit 2cbca22

Please sign in to comment.