Skip to content

Commit

Permalink
Merge pull request #1 from utopia-php/dev
Browse files Browse the repository at this point in the history
Feat: DB proxy
  • Loading branch information
eldadfux committed Feb 27, 2024
2 parents a58b629 + 8b194dc commit 85812cd
Show file tree
Hide file tree
Showing 18 changed files with 3,463 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
UTOPIA_DATA_API_ENV=development
UTOPIA_DATA_API_SECRET=proxy-secret-key
UTOPIA_DATA_API_SECRET_CONNECTION=mariadb://root:password@mariadb:3306/appwrite?pool_size=256
UTOPIA_DATA_API_LOGGING_PROVIDER=
UTOPIA_DATA_API_LOGGING_CONFIG=
16 changes: 16 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "CodeQL"

on: [pull_request]
jobs:
lint:
name: CodeQL
runs-on: ubuntu-latest

steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Run CodeQL
run: |
docker run --rm -v $PWD:/app composer sh -c \
"composer install --profile --ignore-platform-reqs && composer check"
16 changes: 16 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Linter"

on: [pull_request]
jobs:
lint:
name: Linter
runs-on: ubuntu-latest

steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Run Linter
run: |
docker run --rm -v $PWD:/app composer sh -c \
"composer install --profile --ignore-platform-reqs && composer lint"
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Release"

on:
release:
types: [published]

env:
IMAGE_NAME: utopia-php/database-proxy
TAG: ${{ github.event.release.tag_name }}
USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2

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

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

- name: Login to DockerHub
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USERNAME }}
password: ${{ env.PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v4
with:
build-args: |
UTOPIA_DATA_API_VERSION=${{ env.TAG }}
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
context: .
push: true
tags: ${{ env.IMAGE_NAME }}:latest,${{ env.IMAGE_NAME }}:${{ env.TAG }}
33 changes: 33 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Tests"

on: [pull_request]
jobs:
tests:
name: Tests
runs-on: ubuntu-latest

steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Start Test Stack
run: |
export COMPOSE_INTERACTIVE_NO_CLI
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
export BUILDKIT_PROGRESS=plain
docker pull composer:2.0
docker compose build
docker compose up -d
sleep 60
- name: Doctor
run: |
docker compose logs
docker ps
docker network ls
- name: Run Tests
run: |
docker run --rm -v $PWD:/app --network data-api_database -w /app phpswoole/swoole:4.8.12-php8.1-alpine sh -c \
"composer install --profile --ignore-platform-reqs && composer test"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
/.idea/
.phpunit.cache
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"Tests\\ProxyTest::testSecret":8,"Tests\\ProxyTest::testDefaultDatabase":7,"Tests\\ProxyTest::testNamespace":7,"Tests\\ProxyTest::testTimeout":7,"Tests\\ProxyTest::testAuth":7,"Tests\\ProxyTest::testMock":8,"Tests\\ProxyTest::testPing":7,"Tests\\ProxyTest::testExists":7},"times":{"Tests\\ProxyTest::testSecret":0.005,"Tests\\ProxyTest::testDefaultDatabase":0.009,"Tests\\ProxyTest::testNamespace":0.018,"Tests\\ProxyTest::testTimeout":0.005,"Tests\\ProxyTest::testAuth":0.056,"Tests\\ProxyTest::testMock":0.043,"Tests\\ProxyTest::testPing":0.003,"Tests\\ProxyTest::testExists":0.022}}
89 changes: 89 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Install PHP libraries
FROM composer:2.0 as composer

WORKDIR /usr/local/src/

COPY composer.lock /usr/local/src/
COPY composer.json /usr/local/src/

RUN composer install --ignore-platform-reqs --optimize-autoloader \
--no-plugins --no-scripts --prefer-dist

# Prepare generic compiler
FROM php:8.1.25-cli-alpine3.16 as compile

ENV PHP_SWOOLE_VERSION="v5.1.0" \
PHP_MONGODB_VERSION="1.16.1"

RUN \
apk add --no-cache --virtual .deps \
make \
automake \
autoconf \
gcc \
g++ \
git \
openssl-dev

RUN docker-php-ext-install sockets

# Compile Swoole
FROM compile AS swoole

RUN \
git clone --depth 1 --branch $PHP_SWOOLE_VERSION https://github.com/swoole/swoole-src.git && \
cd swoole-src && \
phpize && \
./configure --enable-sockets --enable-http2 --enable-openssl && \
make && make install && \
cd ..

# Mongodb Extension
FROM compile as mongodb
RUN \
git clone --depth 1 --branch $PHP_MONGODB_VERSION https://github.com/mongodb/mongo-php-driver.git && \
cd mongo-php-driver && \
git submodule update --init && \
phpize && \
./configure && \
make && make install

# Proxy
FROM php:8.1.25-cli-alpine3.16 as final

ARG UTOPIA_DATA_API_VERSION
ENV UTOPIA_DATA_API_VERSION=$UTOPIA_DATA_API_VERSION

LABEL maintainer="team@appwrite.io"

RUN \
apk update \
&& apk add --no-cache --virtual .deps \
make \
automake \
autoconf \
gcc \
g++ \
curl-dev \
&& apk add --no-cache \
libstdc++ \
postgresql-dev \
&& docker-php-ext-install sockets pdo_mysql pdo_pgsql \
&& apk del .deps \
&& rm -rf /var/cache/apk/*

WORKDIR /usr/local/

# Source code
COPY ./app /usr/local/app

# Extensions and libraries
COPY --from=composer /usr/local/src/vendor /usr/local/vendor
COPY --from=swoole /usr/local/lib/php/extensions/no-debug-non-zts-20210902/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/
COPY --from=mongodb /usr/local/lib/php/extensions/no-debug-non-zts-20210902/mongodb.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/

RUN echo extension=swoole.so >> /usr/local/etc/php/conf.d/swoole.ini

EXPOSE 80

CMD [ "php", "app/http.php" ]
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Utopia PHP Database Proxy
# Utopia PHP Data API

Build:
docker build -t data-api .
Loading

0 comments on commit 85812cd

Please sign in to comment.