Skip to content

Commit

Permalink
Merge pull request #599 from fragforce/dev
Browse files Browse the repository at this point in the history
Update prod - GH actions
  • Loading branch information
gpmidi committed May 9, 2023
2 parents 4d4757c + 9c2f0b2 commit 71192cb
Show file tree
Hide file tree
Showing 33 changed files with 265 additions and 99 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/builder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Builder

env:
BUILD_ARGS: ""

on:
push:
tags:
- v*
branches:
- master
- dev
pull_request:
branches:
- master
- dev

jobs:
build:
name: Build & push docker image
runs-on: ubuntu-latest
env:
IMG_NAME: ${{ github.repository }}
strategy:
max-parallel: 4
matrix:
dockerfile: [ "web", "worker", "beat" ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Debug
run: |
echo "github.ref -> {{ github.ref }}"
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ env.IMG_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value={{sha}},enable=${{ github.ref_type != 'tag' }}
- name: Login to GitHub Container Registry
if: env.BUILD_ARGS != '--test'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile.${{ matrix.dockerfile }}
push: ${{ github.event.base_ref =='refs/heads/main' && github.ref_type == 'tag' && !startsWith(github.ref, 'refs/tags/v0.')}}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
37 changes: 37 additions & 0 deletions Dockerfile.beat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM python:3.10-slim as base

# Setup env
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1
RUN apt-get update && apt-get install -y --no-install-recommends python3-lxml libpq-dev python3-dev postgresql postgresql-client

FROM base AS python-deps

# Install pipenv and compilation dependencies
RUN pip install --upgrade pip
RUN pip install pipenv asdf
RUN apt-get update && apt-get install -y --no-install-recommends gcc git python-dev postgresql postgresql-client

# Install python dependencies in /.venv
COPY Pipfile .
COPY Pipfile.lock .
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy


FROM base AS runtime

# Copy virtual env from python-deps stage
COPY --from=python-deps /.venv /.venv
ENV PATH="/.venv/bin:$PATH"

# Create and switch to a new user
RUN useradd --create-home appuser
WORKDIR /home/appuser
USER appuser

# Install application into container
COPY . .

CMD [ "celery", "-A", "fforg", "worker", "-l", "${CELERY_LOG_LEVEL:-INFO}", "--autoscale=1,1", "--beat" ]
37 changes: 37 additions & 0 deletions Dockerfile.web
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM python:3.10-slim as base

# Setup env
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1
RUN apt-get update && apt-get install -y --no-install-recommends python3-lxml libpq-dev python3-dev postgresql postgresql-client

FROM base AS python-deps

# Install pipenv and compilation dependencies
RUN pip install --upgrade pip
RUN pip install pipenv asdf
RUN apt-get update && apt-get install -y --no-install-recommends gcc git python-dev postgresql postgresql-client

# Install python dependencies in /.venv
COPY Pipfile .
COPY Pipfile.lock .
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy


FROM base AS runtime

# Copy virtual env from python-deps stage
COPY --from=python-deps /.venv /.venv
ENV PATH="/.venv/bin:$PATH"

# Create and switch to a new user
RUN useradd --create-home appuser
WORKDIR /home/appuser
USER appuser

# Install application into container
COPY . .

CMD [ "gunicorn", "fforg.wsgi" ]
37 changes: 37 additions & 0 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM python:3.10-slim as base

# Setup env
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1
RUN apt-get update && apt-get install -y --no-install-recommends python3-lxml libpq-dev python3-dev postgresql postgresql-client

FROM base AS python-deps

# Install pipenv and compilation dependencies
RUN pip install --upgrade pip
RUN pip install pipenv asdf
RUN apt-get update && apt-get install -y --no-install-recommends gcc git python-dev postgresql postgresql-client

# Install python dependencies in /.venv
COPY Pipfile .
COPY Pipfile.lock .
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy


FROM base AS runtime

# Copy virtual env from python-deps stage
COPY --from=python-deps /.venv /.venv
ENV PATH="/.venv/bin:$PATH"

# Create and switch to a new user
RUN useradd --create-home appuser
WORKDIR /home/appuser
USER appuser

# Install application into container
COPY . .

CMD [ "celery", "-A", "fforg", "worker", "-l", "${CELERY_LOG_LEVEL:-INFO}", "--autoscale=6,2" ]
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ six = "*"
tiltify2 = {git = "https://github.com/gpmidi/tiltify-v2-api-python.git", ref = "develop-v3", editable = true}

[dev-packages]

Loading

0 comments on commit 71192cb

Please sign in to comment.