Skip to content

Commit 45fa746

Browse files
authored
Merge pull request #1 from limelight-development/feat/php85
Feat/php85
2 parents 78b8cd0 + b6313ae commit 45fa746

File tree

6 files changed

+72
-59
lines changed

6 files changed

+72
-59
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v6
1212
- name: Insert to demo database (using env)
1313
uses: ./
1414
env:

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
FROM burnett0/alpine-php7-cli-pdo-mysql
1+
FROM burnett0/alpine-php85-cli-pdo-mysql
22

33
COPY db-processor /
4-
COPY docker/entrypoint.sh /
54

6-
RUN chmod +x /entrypoint.sh
5+
RUN chmod +x /db-processor
76

8-
ENTRYPOINT ["/entrypoint.sh"]
7+
ENTRYPOINT ["/db-processor"]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

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

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,24 @@
3535
# [[input-pass]INPUT_PASS] Set the mysql password
3636
# The default value is env INPUT_PASS
3737
# Format: String
38-
# [[input-tabl]INPUT_TABL] Set the mysql table, eg: db.tbl
38+
# [[input-tabl]INPUT_TABL] Set the mysql db+table, eg: db.tbl
3939
# The default value is env INPUT_TABL
4040
# Format: String
4141
# [[input-debug]INPUT_DEBUG] Toggle the debug mode
4242
# The default value is env INPUT_DEBUG
4343
# or false
4444
# Format: Boolean/Integer
45+
# [[input-timeo]INPUT_TIMEO] Set the max timeout for PDO
46+
# The default value is env INPUT_TIMEO
47+
# or 5
48+
# Format: Integer
4549
#
4650
# EXAMPLES
4751
# ./db-processor "column1=value1;column2=value2" ...
4852
#
4953
#================================================================
5054
#- IMPLEMENTATION
51-
#- version 1.0.0
55+
#- version 3.0.0
5256
#- author Steven Agyekum <[email protected]>
5357
#- copyright Copyright (c) Limelight Gaming Ltd.
5458
#- license MIT License
@@ -64,48 +68,31 @@ We use this product in our CD workflows for tracking some commit messages.
6468

6569
## Usage
6670

67-
### Standalone
68-
69-
Requirements:
70-
71-
- MySQL client
72-
- PHP 7 with PDO extension enabled
73-
74-
Permissions:
71+
Use it as standalone, docker container, or GH action:
7572

76-
``chmod +x ./db-processor``
77-
78-
Execution:
79-
80-
```
81-
./db-processor <args>
82-
```
73+
### Docker
8374

84-
or
75+
Build the container using the Dockerfile
8576

77+
```bash
78+
docker build -t db-processor .
8679
```
87-
./db-processor
88-
```
8980

90-
when using environment variables.
81+
and run:
9182

92-
### Docker
93-
94-
Build the container using the Dockerfile and run:
95-
96-
```
97-
docker run -e INPUT_MAPS="" -e INPUT_HOST="" -e INPUT_PORT="" -e INPUT_USER="" -e INPUT_PASS="" -e INPUT_TABL="" -e INPUT_DEBUG=true
83+
```bash
84+
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
9885
```
9986

10087
### Github Actions
10188

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

104-
```
91+
```bash
10592
steps:
106-
- uses: actions/checkout@v2
93+
- uses: actions/checkout@v6
10794
- name: Insert to database
108-
uses: limelight-development/db-processor@2.0
95+
uses: limelight-development/db-processor@3.0
10996
with:
11097
maps: column1=value1;column2=value2;
11198
host: ${{ secrets.MYSQL_HOST }}
@@ -118,11 +105,11 @@ You can run this action by using the ``with:`` block
118105

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

121-
```
108+
```bash
122109
steps:
123-
- uses: actions/checkout@v2
110+
- uses: actions/checkout@v6
124111
- name: Insert to database
125-
uses: limelight-development/db-processor@2.0
112+
uses: limelight-development/db-processor@3.0
126113
env:
127114
INPUT_MAPS: column1=value1;column2=value2;
128115
INPUT_HOST: ${{ secrets.MYSQL_HOST }}
@@ -133,9 +120,9 @@ or by using the ``env:`` block for environment variables
133120
INPUT_DEBUG: true
134121
```
135122

136-
**Full example:**
123+
**Full action example:**
137124

138-
```
125+
```bash
139126
name: CI
140127

141128
on: [push]
@@ -146,9 +133,9 @@ jobs:
146133
runs-on: ubuntu-latest
147134

148135
steps:
149-
- uses: actions/checkout@v2
136+
- uses: actions/checkout@v6
150137
- name: Insert to database
151-
uses: limelight-development/db-processor@2.0
138+
uses: limelight-development/db-processor@3.0
152139
with:
153140
maps: column1=value1;column2=value2;
154141
host: ${{ secrets.MYSQL_HOST }}
@@ -157,11 +144,36 @@ jobs:
157144
pass: ${{ secrets.MYSQL_PASS }}
158145
tabl: ${{ secrets.MYSQL_TABL }}
159146
debug: true
147+
timeo: 5
160148

161149
```
162-
---
163150

164-
Check synopsis above to get an example.
151+
### Standalone
152+
153+
Requirements:
154+
155+
- MySQL client
156+
- PHP 8.5+ with PDO extension enabled
157+
158+
Permissions:
159+
160+
``chmod +x ./db-processor``
161+
162+
Execution:
163+
164+
```
165+
./db-processor <args>
166+
```
167+
168+
or
169+
170+
```
171+
./db-processor
172+
```
173+
174+
when using environment variables.
175+
176+
---
165177

166178
## Demo
167179

db-processor

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,24 @@
3333
# [[input-pass]INPUT_PASS] Set the mysql password
3434
# The default value is env INPUT_PASS
3535
# Format: String
36-
# [[input-tabl]INPUT_TABL] Set the mysql table, eg: db.tbl
36+
# [[input-tabl]INPUT_TABL] Set the mysql db+table, eg: db.tbl
3737
# The default value is env INPUT_TABL
3838
# Format: String
3939
# [[input-debug]INPUT_DEBUG] Toggle the debug mode
4040
# The default value is env INPUT_DEBUG
4141
# or false
4242
# Format: Boolean/Integer
43+
# [[input-timeo]INPUT_TIMEO] Set the max timeout for PDO
44+
# The default value is env INPUT_TIMEO
45+
# or 5
46+
# Format: Integer
4347
#
4448
# EXAMPLES
4549
# ./db-processor "column1=value1;column2=value2" ...
4650
#
4751
#================================================================
4852
#- IMPLEMENTATION
49-
#- version 1.0.0
53+
#- version 3.0.0
5054
#- author Steven Agyekum <[email protected]>
5155
#- copyright Copyright (c) Limelight Gaming Ltd.
5256
#- license MIT License
@@ -64,6 +68,7 @@ $INPUT_USER = $ARGV[4] ?? env("INPUT_USER") ?: err('ERR_NO_INPUT_USER', 4);
6468
$INPUT_PASS = $ARGV[5] ?? env("INPUT_PASS") ?: err('ERR_NO_INPUT_PASS', 5);
6569
$INPUT_TABL = $ARGV[6] ?? env("INPUT_TABL") ?: err('ERR_NO_INPUT_TABL', 6);
6670
$INPUT_DEBUG = $ARGV[7] ?? env("INPUT_DEBUG") ?: 0;
71+
$INPUT_TIMEO = $ARGV[8] ?? env("INPUT_TIMEO") ?: 5;
6772

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

84-
$KEYS = join($KEYS, ',');
89+
$KEYS = implode(',', $KEYS);
8590

8691
# Invoke debug mode
8792
debug($INPUT_DEBUG);
8893

8994
# Insert into database
9095
try
9196
{
92-
$DB = new PDO("mysql:host=${INPUT_HOST};port=${INPUT_PORT}", $INPUT_USER, $INPUT_PASS);
93-
$DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
94-
$DB->prepare("INSERT INTO ${INPUT_TABL} SET ${KEYS};")->execute($VALS);
97+
$DB = (new PDO("mysql:host=${INPUT_HOST};port=${INPUT_PORT}", $INPUT_USER, $INPUT_PASS, [
98+
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
99+
PDO::ATTR_TIMEOUT => $INPUT_TIMEO,
100+
]))
101+
->prepare("INSERT INTO ${INPUT_TABL} SET ${KEYS};")->execute($VALS);
95102
}
96103
catch(PDOException $e)
97104
{
@@ -122,13 +129,13 @@ function debug($mode)
122129

123130
if(!$mode) return;
124131

125-
echo "[KEYMAPPING]-arg extracted:";
132+
echo "[KEYMAPPING]-arg extracted: ";
126133
print_r($MAPS);
127134

128-
echo "\nProcessed SQL Query:\n";
135+
echo "\nSQL Query:\n";
129136
echo "INSERT INTO ${INPUT_TABL} SET ${KEYS};";
130137

131-
echo "\nPrepared-Statement values:";
138+
echo "\nPrepared-Statement values: ";
132139
print_r($VALS);
133140
}
134141
?>

docker/entrypoint.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)