Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: DB proxy #1

Merged
merged 33 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
353a2e7
Implement DB proxy
Meldiron Oct 16, 2023
2a8fb48
linter fix
Meldiron Oct 16, 2023
1fb9ad2
Remove leftover
Meldiron Oct 16, 2023
767361d
Add tests, address PR comments
Meldiron Oct 17, 2023
496ff76
Rename endpoints, add pool
Meldiron Oct 18, 2023
9a64f76
Remove memory limit
Meldiron Oct 18, 2023
bd8c0c2
Improve tests
Meldiron Oct 19, 2023
3146380
More auth roles tests
Meldiron Oct 19, 2023
02a45e6
PR review changes
Meldiron Nov 20, 2023
eeedcfc
PR review changes
Meldiron Nov 20, 2023
2b56bf9
Remove unnessessary endpoints
Meldiron Dec 9, 2023
2f54840
getDocument queries as string
fogelito Dec 9, 2023
c0cd587
Merge remote-tracking branch 'origin/dev' into dev
fogelito Dec 9, 2023
6fa0086
json_encode queries
fogelito Dec 9, 2023
0caa0a1
json_encode queries
fogelito Dec 9, 2023
6fb801b
json_encode queries
fogelito Dec 9, 2023
9a28cf2
Count endpoints.php
fogelito Dec 10, 2023
adcd7d3
Error exceptions
fogelito Dec 10, 2023
df736a6
No reference
fogelito Dec 10, 2023
43cc75c
Build command
fogelito Dec 13, 2023
9f76dee
composer.lock
fogelito Dec 13, 2023
0477586
PR review changes
Meldiron Jan 3, 2024
9755039
Fix failinig tests
Meldiron Jan 3, 2024
a8ae3a3
Changes after HTTP and Auth refactor
Meldiron Jan 27, 2024
c8adf31
Rename to data API
Meldiron Jan 29, 2024
b12bc38
Update readme
Meldiron Jan 29, 2024
4ea8dc1
Rework to have 1 endpoint only
Meldiron Feb 22, 2024
6aa2492
Fix CI/CD tests
Meldiron Feb 22, 2024
c42c4ae
Fix document convertion
Meldiron Feb 22, 2024
b44c0e9
Add support for Query
Meldiron Feb 22, 2024
a369456
WIP: Update to raw queries
Meldiron Feb 23, 2024
44a8f0b
Fix timeouts and serialize params
Meldiron Feb 27, 2024
8b194dc
Fix code quality
Meldiron Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Meldiron marked this conversation as resolved.
Show resolved Hide resolved

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
Loading