Skip to content

Commit

Permalink
Add Dockerfile and build workflow
Browse files Browse the repository at this point in the history
Co-authored-by: Jake Wagoner <jakewagoneredu@gmail.com>
  • Loading branch information
JackWilb and JakeWags committed Jan 11, 2024
1 parent 430688b commit 41f6b97
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
42 changes: 42 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file builds the Docker image and pushes it to ghcr.io
# It is triggered on every release
# The build will run for multiple platforms (amd64, arm64, armv7)
# The build will run on multiple LTS versions of Django (3.2, 4.2)
# The build will run on multiple versions of Python (3.8, 3.9, 3.10), which will be configured in the matrix and pinned to the LTS versions of Django

name: Build Image

on:
release:
types: [published]

jobs:
build-matrix:
strategy:
fail-fast: false
matrix:
software-versions: [
{"python-version": 3.9, "django-version": 3.2},
{"python-version": 3.12, "django-version": 4.2}
]
platform: [amd64, arm64]
poetry-version: [1.7]
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4

- name: Copy from django${{ matrix.software-versions.django-version }} directory to root
run: cp -r django${{ matrix.software-versions.django-version }}/* .

- name: Replace Python Version in Dockerfile
run: sed -i "s/PYTHON_VERSION/${{ matrix.software-versions.python-version }}/g" Dockerfile

- name: Replace the Django Version in Dockerfile
run: sed -i "s/DJANGO_VERSION/${{ matrix.software-versions.django-version }}/g" Dockerfile

- name: Build the image
run: docker buildx build --platform linux/${{ matrix.platform }} --push -t ghcr.io/visdesignlab/django-image:${{matrix.software-versions.django-version}}-${{ github.ref_name }} .



26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:PYTHON_VERSION-slim

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential libpq-dev python3-dev default-libmysqlclient-dev \
&& rm -rf /var/lib/apt/lists/*

COPY ./djangoDJANGO_VERSION/* /install/
WORKDIR /install

RUN pip3 install poetry
RUN poetry install

VOLUME /app
WORKDIR /app

COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

VOLUME /app
WORKDIR /app

EXPOSE 8000
ENTRYPOINT ["/entrypoint.sh"]
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# django-image
# django-image

Django container:
GHCR
2 Major versions of Django at once
Each major version of Django will be pinned to a python version
Image needs to allow installing additional dependencies inside of it for each project, but should come with a comprehensive django base (CORS, mysql, pgsql, oauth package, poetry, gunicorn)
15 changes: 15 additions & 0 deletions django3.2/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "django32"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
django = ">=3.2,<4.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
15 changes: 15 additions & 0 deletions django4.2/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "django42"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
django = ">=4.2,<5.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/bash

echo 'entrypoint.sh'
echo `pwd`

0 comments on commit 41f6b97

Please sign in to comment.