Skip to content

Commit 5d43053

Browse files
authored
Merge pull request #142 from nohn/chore/improve-build-process
allow building self contained using Docker instead of github actions
2 parents 4b37e83 + fd88f7f commit 5d43053

5 files changed

Lines changed: 55 additions & 25 deletions

File tree

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
vendor/
2+
.git/
3+
.idea/
4+
log/*.log
5+
tmp/*
6+
!tmp/.gitkeep
7+
!log/.gitkeep

.github/workflows/ci.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@ jobs:
1111
steps:
1212
- name: Pull Code
1313
uses: actions/checkout@v3
14-
- name: Setup PHP
15-
uses: shivammathur/setup-php@v2
16-
with:
17-
php-version: 8.3
18-
extensions: imagick
19-
coverage: xdebug
20-
tools: phpstan
21-
- name: Install dependencies
22-
run: sudo apt install tesseract-ocr
23-
- name: Install composer dependencies
24-
run: composer update --no-ansi --no-interaction --no-progress
25-
- name: Run PHPStan
26-
run: phpstan analyse src
27-
- name: Run unit tests
28-
run: vendor/bin/phpunit tests
2914
- name: Set up QEMU
3015
uses: docker/setup-qemu-action@v2
3116
- name: Set up Docker Buildx

Dockerfile

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
1-
FROM php:8.3.12-cli
1+
FROM php:8.3.12-cli AS base
22
RUN apt-get update \
3-
&& apt-get install -y libmagickwand-dev tesseract-ocr \
3+
&& apt-get install -y libmagickwand-dev tesseract-ocr unzip \
44
&& pecl install imagick \
55
&& docker-php-ext-enable imagick
6-
COPY ./classes /usr/src/watermeter/classes
7-
COPY ./log /usr/src/watermeter/log
8-
COPY ./public /usr/src/watermeter/public
9-
COPY ./src /usr/src/watermeter/src
10-
COPY ./vendor /usr/src/watermeter/vendor
6+
7+
FROM base AS build
8+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
9+
WORKDIR /usr/src/watermeter
10+
COPY composer.json ./
11+
RUN composer install --no-ansi --no-interaction --no-progress
12+
COPY . .
13+
14+
# Run Static Analysis
15+
RUN vendor/bin/phpstan analyse src classes
16+
# Run Unit Tests
17+
RUN vendor/bin/phpunit tests
18+
19+
FROM base AS final
20+
WORKDIR /usr/src/watermeter
21+
22+
# Ensure that the build stage (tests and PHPStan) has been executed successfully
23+
# by copying a file from it. This creates a dependency so Docker won't skip it.
24+
COPY --from=build /usr/src/watermeter/composer.json /usr/src/watermeter/composer.json
25+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
26+
COPY composer.json ./
27+
28+
# Do not install dev dependencies on final build
29+
RUN composer install --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress
30+
31+
# Create necessary directories and set permissions
32+
RUN mkdir -p log/debug log/error tmp \
33+
&& chmod -R 777 log tmp
34+
35+
COPY classes/ ./classes/
36+
COPY public/ ./public/
37+
COPY src/ ./src/
38+
COPY LICENSE README.md ./
39+
1140
WORKDIR /usr/src/watermeter/public
1241
CMD [ "php", "-S", "0.0.0.0:3000" ]

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This is only a quick introduction to setting up and configuring watermeter. A mo
1212

1313
### Installation
1414

15-
#### Using Docker Compose (recommended)
15+
#### Using Docker Compose and Docker Hub (recommended)
1616

1717
```yaml
1818
version: "3.5"
@@ -27,6 +27,14 @@ services:
2727
- "3000:3000"
2828
```
2929
30+
#### Building locally
31+
32+
If you want to build the Docker image locally, you can use the following command:
33+
34+
```bash
35+
docker build . -t nohn/watermeter
36+
```
37+
3038
### Configuration
3139

3240
You can access the configuration tool http://watermeter:3000/configure.php. The interface should be self explanatory. Source Image can be either in local filesystem or any HTTP(S) resource.
@@ -58,4 +66,4 @@ Consider a [gift](https://www.amazon.de/hz/wishlist/ls/3HYH6NR8ZI0WI?ref_=wl_sha
5866

5967
## License
6068

61-
analogmeterreader is released under the [GNU Affero General Public License](LICENSE).
69+
watermeter is released under the [GNU Affero General Public License](LICENSE).

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"ext-json": ">=8.1"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^11.3"
22+
"phpunit/phpunit": "^11.3",
23+
"phpstan/phpstan": "^2.1"
2324
},
2425
"support": {
2526
"issues": "https://github.com/nohn/watermeter/issues"

0 commit comments

Comments
 (0)