Skip to content

Commit

Permalink
feat(poetry): use poetry as the dependency manager (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
MagneticNeedle authored Jul 10, 2023
2 parents 6c9617f + cd9c28e commit 37b46a5
Show file tree
Hide file tree
Showing 30 changed files with 2,190 additions and 857 deletions.
5 changes: 2 additions & 3 deletions bfportal/.dockerignore → .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
*.sqlite3

# Python and others
__pycache__
__pycache__/
*.pyc
.DS_Store
*.swp
/venv/
/tmp/
/.vagrant/
/Vagrantfile.local
node_modules/
node_modules
/npm-debug.log
/.idea/
.vscode
coverage
.python-version

# Distribution / packaging
.Python
env/
Expand Down
File renamed without changes.
61 changes: 32 additions & 29 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,44 @@ on:
branches:
- main
- production
paths:
- 'bfportal/**'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
production-deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./bfportal
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: nelonoel/[email protected]

- name: Build image
run: docker build . --file Dockerfile --tag $BRANCH_NAME

- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/$BRANCH_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $BRANCH_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Login to container registry
uses: docker/login-action@v2
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ${{ env.REGISTRY }} # ghcr.io

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/$BRANCH_NAME
# ghcr.io/battlefield-portal-community/bfportal.gg/production:latest

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

- name: Build and Push Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If you already have experience with django/wagtail, understanding the backend wi


- ### Python
- Refer to [readme.md](/readme.md#how-to-run-locally)
- Refer to [readme.md](/README.md#how-to-run-locally)
- install pre-commit checks by running (**make sure the Virtual Enviroment is activated !!**)
```
pre-commit install
Expand Down
59 changes: 59 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Use an official Python runtime based on Debian 10 "buster" as a parent image.
FROM python:3.11-buster as builder
RUN pip install poetry==1.5.1
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1

WORKDIR /venv
RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends git
RUN touch README.md

COPY ["pyproject.toml", "poetry.lock", "./"]
RUN poetry config installer.max-workers 10
RUN poetry install --without dev --no-root --no-cache

FROM node:latest as node_base
RUN echo "NODE Version:" && node --version
RUN echo "NPM Version:" && npm --version

FROM python:3.11-slim-buster as dev

WORKDIR /app
RUN useradd --create-home wagtail

# Port used by this container to serve HTTP.
EXPOSE 8000
# Install system packages required by Wagtail and Django.
RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \
build-essential \
libpq-dev \
libmariadbclient-dev \
libjpeg62-turbo-dev \
zlib1g-dev \
libwebp-dev \
&& rm -rf /var/lib/apt/lists/*
# Set environment variables.
# 1. Force Python stdout and stderr streams to be unbuffered.
# 2. Set PORT variable that is used by Gunicorn. This should match "EXPOSE"
# command.
ENV PYTHONUNBUFFERED=1 \
PORT=8000 \
PYTHONDONTWRITEBYTECODE=1 \
USER="wagtail" \
VIRTUAL_ENV=/venv/.venv

ENV PATH="${VIRTUAL_ENV}/bin:${PATH}:/home/wagtail/.local/bin"
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

# Copy the source code of the project into the container.
COPY ./bfportal ./

FROM dev as final
COPY --chown=wagtail:wagtail --from=node_base /usr/local/bin /usr/local/bin
COPY --chown=wagtail:wagtail --from=node_base /usr/local/lib/node_modules/npm /usr/local/lib/node_modules/npm

ENV NPM_BIN_PATH = "/usr/local/bin/npm"
RUN python manage.py tailwind install --no-input;
RUN python manage.py tailwind build --no-input
RUN python manage.py collectstatic --noinput --clear
File renamed without changes.
66 changes: 0 additions & 66 deletions bfportal/Dockerfile

This file was deleted.

4 changes: 1 addition & 3 deletions bfportal/bfportal/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"wagtail.admin",
"wagtail.contrib.routable_page",
"wagtail.api.v2",
"wagtail_color_panel",
"modelcluster",
"taggit",
"dal",
Expand All @@ -62,10 +61,9 @@
"django_browser_reload",
"widget_tweaks",
"embed_video",
"django_extensions",
"django_extensions", # todo: triage if we really need this
"wagtailsvg",
"wagtail.contrib.modeladmin",
"generic_chooser",
"wagtailautocomplete",
"ajax_select",
"markdownx",
Expand Down
41 changes: 0 additions & 41 deletions bfportal/core/migrations/0017_auto_20220127_1533.py

This file was deleted.

Loading

0 comments on commit 37b46a5

Please sign in to comment.