Skip to content

Commit

Permalink
Adds docker image build
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Aug 29, 2024
1 parent 593d91a commit 2ca4f5b
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 4 deletions.
71 changes: 71 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
ARG ROAD_RUNNER_IMAGE=2024.2.0
ARG DOLT_IMAGE=1.42.8

# Build dolt binary
FROM dolthub/dolt:$DOLT_IMAGE as dolt
# Build rr binary
FROM ghcr.io/roadrunner-server/roadrunner:$ROAD_RUNNER_IMAGE as rr
# Clone the project
FROM alpine/git as git

ARG REPOSITORY=https://github.com/llm-agents-php/sample-app.git
ARG BRANCH=main
RUN git clone -b $BRANCH $REPOSITORY /app

FROM php:8.3-cli-alpine3.18

RUN apk add --no-cache $PHPIZE_DEPS \
curl \
libcurl \
wget \
libzip-dev \
libmcrypt-dev \
libxslt-dev \
libxml2-dev \
openssl-dev \
icu-dev \
zip \
unzip \
linux-headers

RUN docker-php-ext-install \
opcache \
zip \
dom \
sockets

# PDO database drivers support
RUN docker-php-ext-install pdo_mysql

COPY --from=git /app /app
COPY --from=rr /usr/bin/rr /app
COPY --from=dolt /usr/local/bin/dolt /app
COPY --from=composer /usr/bin/composer /usr/bin/composer

ARG APP_VERSION=v1.0
ENV COMPOSER_ALLOW_SUPERUSER=1

WORKDIR /app

RUN composer config --no-plugins allow-plugins.spiral/composer-publish-plugin false
RUN composer install --no-dev

WORKDIR /app

RUN mkdir .db
RUN ./dolt --data-dir=.db sql -q "create database llm;"

ENV APP_ENV=prod
ENV DEBUG=false
ENV VERBOSITY_LEVEL=verbose
ENV ENCRYPTER_KEY=def00000232ae92c8e8ec0699093fa06ce014cd48d39c3c62c279dd947db084e56ee48b5c91cebc1c5abe53f7755021d09043757561c244c1c0c765cfeb5db33eb45a903
ENV MONOLOG_DEFAULT_CHANNEL=roadrunner
ENV MONOLOG_DEFAULT_LEVEL=INFO
ENV APP_VERSION=$APP_VERSION
ENV RR_LOG_LEVEL=error

LABEL org.opencontainers.image.source=$REPOSITORY
LABEL org.opencontainers.image.description="LL Agents PHP"
LABEL org.opencontainers.image.licenses=MIT

CMD ./rr serve -c .rr.yaml
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

patreon: butschster
47 changes: 47 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Docker Image CI

on:
release:
types:
- created

jobs:
build-release:
if: "!github.event.release.prerelease"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: 'Get Previous tag'
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
fallback: v0.1

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_LOGIN }}
password: ${{ secrets.GHCR_PASSWORD }}

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

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

- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: ./
platforms: linux/amd64,linux/arm64
file: ./.docker/Dockerfile
push: true
build-args: |
APP_VERSION=${{ steps.previoustag.outputs.tag }}
tags:
ghcr.io/${{ github.repository }}:latest, ghcr.io/${{ github.repository }}:${{ steps.previoustag.outputs.tag }}
2 changes: 1 addition & 1 deletion .rr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kv:

server:
on_init:
command: 'php app.php migrate'
command: 'php app.php migrate --force'
command: 'php app.php'
relay: pipes

Expand Down
26 changes: 23 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
###########################
# Docker #
###########################
start:
docker compose up --remove-orphans -d;

up: start

stop:
docker compose stop;

down:
docker compose down;

restart:
docker compose restart;

bash:
docker compose exec app /bin/sh;

###########################
# Local development #
###########################
init: init-db init-rr

# Install dolt database
Expand All @@ -21,6 +44,3 @@ init-rr:

clear-cache:
rm -rf runtime/cache;

start:
./rr serve
7 changes: 7 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.7'

services:
app:
build: "./.docker"
environment:
OPENAI_KEY: ${OPENAI_KEY}

0 comments on commit 2ca4f5b

Please sign in to comment.