Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Insert to demo database (using env)
uses: ./
env:
Expand Down
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM burnett0/alpine-php7-cli-pdo-mysql
FROM burnett0/alpine-php85-cli-pdo-mysql

COPY db-processor /
COPY docker/entrypoint.sh /

RUN chmod +x /entrypoint.sh
RUN chmod +x /db-processor

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/db-processor"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-2021 Limelight Gaming Ltd.
Copyright (c) 2019-2026 Limelight Gaming Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
90 changes: 51 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,24 @@
# [[input-pass]INPUT_PASS] Set the mysql password
# The default value is env INPUT_PASS
# Format: String
# [[input-tabl]INPUT_TABL] Set the mysql table, eg: db.tbl
# [[input-tabl]INPUT_TABL] Set the mysql db+table, eg: db.tbl
# The default value is env INPUT_TABL
# Format: String
# [[input-debug]INPUT_DEBUG] Toggle the debug mode
# The default value is env INPUT_DEBUG
# or false
# Format: Boolean/Integer
# [[input-timeo]INPUT_TIMEO] Set the max timeout for PDO
# The default value is env INPUT_TIMEO
# or 5
# Format: Integer
#
# EXAMPLES
# ./db-processor "column1=value1;column2=value2" ...
#
#================================================================
#- IMPLEMENTATION
#- version 1.0.0
#- version 3.0.0
#- author Steven Agyekum <s-8@posteo.mx>
#- copyright Copyright (c) Limelight Gaming Ltd.
#- license MIT License
Expand All @@ -64,48 +68,31 @@ We use this product in our CD workflows for tracking some commit messages.

## Usage

### Standalone

Requirements:

- MySQL client
- PHP 7 with PDO extension enabled

Permissions:
Use it as standalone, docker container, or GH action:

``chmod +x ./db-processor``

Execution:

```
./db-processor <args>
```
### Docker

or
Build the container using the Dockerfile

```bash
docker build -t db-processor .
```
./db-processor
```

when using environment variables.
and run:

### Docker

Build the container using the Dockerfile and run:

```
docker run -e INPUT_MAPS="" -e INPUT_HOST="" -e INPUT_PORT="" -e INPUT_USER="" -e INPUT_PASS="" -e INPUT_TABL="" -e INPUT_DEBUG=true
```bash
docker run --rm -e INPUT_MAPS="" -e INPUT_HOST="" -e INPUT_PORT="3306" -e INPUT_USER="" -e INPUT_PASS="" -e INPUT_TABL="" -e INPUT_DEBUG=true db-processor
```

### Github Actions

You can run this action by using the ``with:`` block

```
```bash
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Insert to database
uses: limelight-development/db-processor@2.0
uses: limelight-development/db-processor@3.0
with:
maps: column1=value1;column2=value2;
host: ${{ secrets.MYSQL_HOST }}
Expand All @@ -118,11 +105,11 @@ You can run this action by using the ``with:`` block

or by using the ``env:`` block for environment variables

```
```bash
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Insert to database
uses: limelight-development/db-processor@2.0
uses: limelight-development/db-processor@3.0
env:
INPUT_MAPS: column1=value1;column2=value2;
INPUT_HOST: ${{ secrets.MYSQL_HOST }}
Expand All @@ -133,9 +120,9 @@ or by using the ``env:`` block for environment variables
INPUT_DEBUG: true
```

**Full example:**
**Full action example:**

```
```bash
name: CI

on: [push]
Expand All @@ -146,9 +133,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Insert to database
uses: limelight-development/db-processor@2.0
uses: limelight-development/db-processor@3.0
with:
maps: column1=value1;column2=value2;
host: ${{ secrets.MYSQL_HOST }}
Expand All @@ -157,11 +144,36 @@ jobs:
pass: ${{ secrets.MYSQL_PASS }}
tabl: ${{ secrets.MYSQL_TABL }}
debug: true
timeo: 5

```
---

Check synopsis above to get an example.
### Standalone

Requirements:

- MySQL client
- PHP 8.5+ with PDO extension enabled

Permissions:

``chmod +x ./db-processor``

Execution:

```
./db-processor <args>
```

or

```
./db-processor
```

when using environment variables.

---

## Demo

Expand Down
25 changes: 16 additions & 9 deletions db-processor
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@
# [[input-pass]INPUT_PASS] Set the mysql password
# The default value is env INPUT_PASS
# Format: String
# [[input-tabl]INPUT_TABL] Set the mysql table, eg: db.tbl
# [[input-tabl]INPUT_TABL] Set the mysql db+table, eg: db.tbl
# The default value is env INPUT_TABL
# Format: String
# [[input-debug]INPUT_DEBUG] Toggle the debug mode
# The default value is env INPUT_DEBUG
# or false
# Format: Boolean/Integer
# [[input-timeo]INPUT_TIMEO] Set the max timeout for PDO
# The default value is env INPUT_TIMEO
# or 5
# Format: Integer
#
# EXAMPLES
# ./db-processor "column1=value1;column2=value2" ...
#
#================================================================
#- IMPLEMENTATION
#- version 1.0.0
#- version 3.0.0
#- author Steven Agyekum <s-8@posteo.mx>
#- copyright Copyright (c) Limelight Gaming Ltd.
#- license MIT License
Expand All @@ -64,6 +68,7 @@ $INPUT_USER = $ARGV[4] ?? env("INPUT_USER") ?: err('ERR_NO_INPUT_USER', 4);
$INPUT_PASS = $ARGV[5] ?? env("INPUT_PASS") ?: err('ERR_NO_INPUT_PASS', 5);
$INPUT_TABL = $ARGV[6] ?? env("INPUT_TABL") ?: err('ERR_NO_INPUT_TABL', 6);
$INPUT_DEBUG = $ARGV[7] ?? env("INPUT_DEBUG") ?: 0;
$INPUT_TIMEO = $ARGV[8] ?? env("INPUT_TIMEO") ?: 5;

# Extract key mappings
$EXPRESSION = "/(?:\b(\w+)\=\b([\w\s=+:.?!+\/\\´'\"§%&$,)(#-]+)\;?)/";
Expand All @@ -81,17 +86,19 @@ foreach( $MAPS as $IDX => $KV )
$VALS[$IDX] = $KV[2];
}

$KEYS = join($KEYS, ',');
$KEYS = implode(',', $KEYS);

# Invoke debug mode
debug($INPUT_DEBUG);

# Insert into database
try
{
$DB = new PDO("mysql:host=${INPUT_HOST};port=${INPUT_PORT}", $INPUT_USER, $INPUT_PASS);
$DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$DB->prepare("INSERT INTO ${INPUT_TABL} SET ${KEYS};")->execute($VALS);
$DB = (new PDO("mysql:host=${INPUT_HOST};port=${INPUT_PORT}", $INPUT_USER, $INPUT_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_TIMEOUT => $INPUT_TIMEO,
]))
->prepare("INSERT INTO ${INPUT_TABL} SET ${KEYS};")->execute($VALS);
}
catch(PDOException $e)
{
Expand Down Expand Up @@ -122,13 +129,13 @@ function debug($mode)

if(!$mode) return;

echo "[KEYMAPPING]-arg extracted:";
echo "[KEYMAPPING]-arg extracted: ";
print_r($MAPS);

echo "\nProcessed SQL Query:\n";
echo "\nSQL Query:\n";
echo "INSERT INTO ${INPUT_TABL} SET ${KEYS};";

echo "\nPrepared-Statement values:";
echo "\nPrepared-Statement values: ";
print_r($VALS);
}
?>
5 changes: 0 additions & 5 deletions docker/entrypoint.sh

This file was deleted.

Loading