Commit 4a783b08 authored by Grant, Josh's avatar Grant, Josh
Browse files

Mitchell suggested to include the argument in the Dockerfile, which was a good idea

parent a2d2e0e1
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
ARG PYTHON_VERSION=3.11
ARG PYGARDEN_INSTALL_TOKEN
FROM --platform=${BUILDARCH} python:${PYTHON_VERSION}-slim AS builder
ARG PYGARDEN_EXTRAS
RUN apt-get update && apt-get install -yqq libpq-dev gcc
WORKDIR /app
COPY requirements.txt.tpl .
RUN sed \
    -e "s|\${PYGARDEN_EXTRAS}|${PYGARDEN_EXTRAS}|" \
    requirements.txt.tpl > requirements.txt && \
    pip install --no-cache-dir --break-system-packages -r requirements.txt && rm requirements.txt requirements.txt.tpl
    pip install --no-cache-dir --break-system-packages -r requirements.txt # && rm requirements.txt requirements.txt.tpl
RUN apt remove -y gcc
+82 −0
Original line number Diff line number Diff line
@@ -35,6 +35,88 @@ A docker image and python package are provided for use as a base image in `docke

`common_package/sql/` contains the .sql files `create_tables.sql` and `fill_tables.sql` which serve as examples for how to initialize a postgres Database in your project (See below in the Creating an extensible Database Python Class section for details in how to create the Python Class.) The `volumes` statement in the docker-compose files runs these sql files once the container is created.

## Docker Installation stuff
# docker-prototype

This repository contains a prototype for a Docker-based development environment
for Python scripts that uses the `pygarden[postgres]` package to allow for easy
interaction with a PostgreSQL database. Additionally, the `requests` package is
used to make HTTP requests to a APIs.

## Getting Started
This project makes extensive use of Docker and Docker Compose to create a
development environment for Python scripts. To get started, follow the steps
below:

1. Create a `.env` file in the root of the project and add the following
   environment variables:
```bash
PYTHON_VERSION=3.11  # choose which version of Python you want to build
PYGARDEN_INSTALL_TOKEN=<your-pygarden-token>  # get a token that will allow you to install pygarden
# optional DB environment variables
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=postgres
```
2. (If using Docker's bake) Create a multiarch-builder and use it
```bash
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx create \
    --name multiarch-builder \
    --driver docker-container \
    --platform linux/amd64,linux/arm64 \
    --use
docker buildx inspect --bootstrap
```

3. Build the Docker image and start the container:

Using Docker Compose:
```bash
source .env  # source the .env file you created above
docker compose build  # build the Docker image
docker compose run pygarden python  # start the container and run the Python REPL
```
or if you are using Docker's bake:
```bash
docker buildx bake --push  # build and push all the targets
docker run --rm -it \
    --env-file .env \
    --platform linux/arm64/v8 \
    --name pygarden \
    savannah.ornl.gov/common/pygarden:${PYTHON_VERSION:-3.12}-postgres-latest \
    python
```

4. From the Python REPL, you can now import the `pygarden` package and interact
   with the PostgreSQL database. For example:
```python
from pygarden.database import Database
from pygarden.mixins.postgres import PostgresMixin
class MyDatabase(PostgresMixin, Database):
    pass
db = MyDatabase()
with db:
    db.execute("SELECT * FROM pg_catalog.pg_tables;")
```

## Getting the Image
The Docker image for this project is hosted on [Savannah](https://savannah.ornl.gov/),
and is tagged with `savannah.ornl.gov/common/pygarden:${PYTHON_VERSION:-3.12}-latest`,
where `${PYTHON_VERSION:-3.12}` is the Python version you want to use. To pull the
image, you can run:
```bash
docker pull savannah.ornl.gov/common/pygarden:${PYTHON_VERSION:-3.12}-latest
```

## Saving the Image to a Tar File
If you want to save the image to a tar file, you can run:
```bash
docker save savannah.ornl.gov/common/pygarden:${PYTHON_VERSION:-3.12}-latest -o pygarden.tar
gzip pygarden.tar  # optionally compress the tar file
```
Now you can transport the image wherever you'd like!

## Releases

To initiate a release, increment the value in `COMMON_VERSION` run `./release.sh release`. This will force checkout develop and run the release process to push to the package registry and container registry.
+0 −2
Original line number Diff line number Diff line
psycopg2-binary
requests~=2.32.3
--extra-index-url https://__token__:$PYGARDEN_INSTALL_TOKEN@code.ornl.gov/api/v4/projects/10568/packages/pypi/simple
pygarden[${PYGARDEN_EXTRAS}]==0.3.8