Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit c5a3fa0

Browse files
authored
223 remove sqlite and docs overhaul (#232)
* Created a Makefile * Makefile works with for loop * Conditional check for tagging semver * Added empty(ish) compose files * Swited to makefile * Hard coded env vars that don't work * Added docker-compose * Better docs * Update README.md * Fixed some docs
1 parent 76a8b71 commit c5a3fa0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+625
-778
lines changed

Dockerfile

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# |_|\_\_|_| |_| |_|\__,_|_|_____|
66
#
77

8-
# Source base [fpm-alpine/apache-debian]
9-
ARG BASE="fpm-alpine"
8+
# Source base [fpm/apache]
9+
ARG BASE="fpm"
1010

1111
###########################
1212
# Shared tools
@@ -16,7 +16,7 @@ ARG BASE="fpm-alpine"
1616
FROM alpine:3.13.5 AS git-dev
1717
ARG KIMAI="1.12"
1818
# I need to do this check somewhere, we discard all but the checkout so doing here doesn't hurt
19-
ADD test-kimai-version.sh /test-kimai-version.sh
19+
ADD assets/test-kimai-version.sh /test-kimai-version.sh
2020
RUN /test-kimai-version.sh
2121
RUN apk add --no-cache git && \
2222
git clone --depth 1 --branch ${KIMAI} https://github.com/kevinpapst/kimai2.git /opt/kimai
@@ -35,7 +35,7 @@ FROM composer:2.0.12 AS composer
3535
###########################
3636

3737
#fpm alpine php extension base
38-
FROM php:7.4.15-fpm-alpine3.13 AS fpm-alpine-php-ext-base
38+
FROM php:7.4.15-fpm-alpine3.13 AS fpm-php-ext-base
3939
RUN apk add --no-cache \
4040
# build-tools
4141
autoconf \
@@ -70,7 +70,7 @@ RUN apk add --no-cache \
7070

7171

7272
# apache debian php extension base
73-
FROM php:7.4.15-apache-buster AS apache-debian-php-ext-base
73+
FROM php:7.4.15-apache-buster AS apache-php-ext-base
7474
RUN apt-get update
7575
RUN apt-get install -y \
7676
libldap2-dev \
@@ -111,13 +111,14 @@ RUN docker-php-ext-install -j$(nproc) xsl
111111

112112

113113
###########################
114-
# fpm-alpine base build
114+
# fpm base build
115115
###########################
116116

117-
# fpm-alpine base build
118-
FROM php:7.4.15-fpm-alpine3.13 AS fpm-alpine-base
117+
# fpm base build
118+
FROM php:7.4.15-fpm-alpine3.13 AS fpm-base
119119
RUN apk add --no-cache \
120120
bash \
121+
coreutils \
121122
freetype \
122123
haveged \
123124
icu \
@@ -140,11 +141,11 @@ HEALTHCHECK --interval=20s --timeout=10s --retries=3 \
140141

141142

142143
###########################
143-
# apache-debian base build
144+
# apache base build
144145
###########################
145146

146-
FROM php:7.4.15-apache-buster AS apache-debian-base
147-
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
147+
FROM php:7.4.15-apache-buster AS apache-base
148+
COPY assets/000-default.conf /etc/apache2/sites-available/000-default.conf
148149
RUN apt-get update && \
149150
apt-get install -y \
150151
bash \
@@ -183,8 +184,9 @@ RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezo
183184
chown -R www-data:www-data /composer
184185

185186
# copy startup script & DB checking script
186-
COPY startup.sh /startup.sh
187-
COPY dbtest.php /dbtest.php
187+
COPY assets/startup.sh /startup.sh
188+
COPY assets/self-test.sh /self-test.sh
189+
COPY assets/dbtest.php /dbtest.php
188190

189191
# copy composer
190192
COPY --from=composer /usr/bin/composer /usr/bin/composer
@@ -225,6 +227,8 @@ ENV DB_PASS=
225227
ENV DB_HOST=
226228
ENV DB_PORT=
227229
ENV DB_BASE=
230+
# If this set then the image will start, run a self test and then exit. It's used for the release process
231+
ENV TEST_AND_EXIT=
228232

229233

230234
VOLUME [ "/opt/kimai/var" ]
@@ -241,7 +245,7 @@ ENTRYPOINT /startup.sh
241245
FROM base AS dev
242246
# copy kimai develop source
243247
COPY --from=git-dev --chown=www-data:www-data /opt/kimai /opt/kimai
244-
COPY monolog-dev.yaml /opt/kimai/config/packages/dev/monolog.yaml
248+
COPY assets/monolog-dev.yaml /opt/kimai/config/packages/dev/monolog.yaml
245249
# do the composer deps installation
246250
RUN export COMPOSER_HOME=/composer && \
247251
composer --no-ansi install --working-dir=/opt/kimai --optimize-autoloader && \
@@ -253,13 +257,14 @@ RUN export COMPOSER_HOME=/composer && \
253257
sed "s/128M/-1/g" /usr/local/etc/php/php.ini-development > /opt/kimai/php-cli.ini && \
254258
sed -i "s/env php/env -S php -c \/opt\/kimai\/php-cli.ini/g" /opt/kimai/bin/console
255259
ENV APP_ENV=dev
260+
ENV DATABASE_URL=
256261
USER www-data
257262

258263
# production build
259264
FROM base AS prod
260265
# copy kimai production source
261266
COPY --from=git-prod --chown=www-data:www-data /opt/kimai /opt/kimai
262-
COPY monolog-prod.yaml /opt/kimai/config/packages/prod/monolog.yaml
267+
COPY assets/monolog-prod.yaml /opt/kimai/config/packages/prod/monolog.yaml
263268
# do the composer deps installation
264269
RUN export COMPOSER_HOME=/composer && \
265270
composer --no-ansi install --working-dir=/opt/kimai --no-dev --optimize-autoloader && \
@@ -269,4 +274,5 @@ RUN export COMPOSER_HOME=/composer && \
269274
mkdir -p /opt/kimai/var/logs && chmod 777 /opt/kimai/var/logs && \
270275
chown -R www-data:www-data /opt/kimai
271276
ENV APP_ENV=prod
277+
ENV DATABASE_URL=
272278
USER www-data

Makefile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
include .env
2+
3+
ifndef TIMEZONE
4+
TIMEZONE := Europe/London
5+
endif
6+
7+
ifndef KIMAI_VERSION
8+
KIMAI_VERSION := master
9+
endif
10+
11+
ZAP := $(shell echo $(KIMAI_VERSION) | egrep -q "[0-9].[0-9]+" && echo matched)
12+
13+
build:
14+
docker build -t kimai2/kimai:fpm-${KIMAI_VERSION}-dev --build-arg KIMAI=${KIMAI_VERSION} --build-arg BASE=fpm --build-arg TZ=${TIMEZONE} --target=dev .
15+
docker build -t kimai2/kimai:fpm-${KIMAI_VERSION}-prod --build-arg KIMAI=${KIMAI_VERSION} --build-arg BASE=fpm --build-arg TZ=${TIMEZONE} --target=prod .
16+
docker build -t kimai2/kimai:apache-${KIMAI_VERSION}-dev --build-arg KIMAI=${KIMAI_VERSION} --build-arg BASE=apache --build-arg TZ=${TIMEZONE} --target=dev .
17+
docker build -t kimai2/kimai:apache-${KIMAI_VERSION}-prod --build-arg KIMAI=${KIMAI_VERSION} --build-arg BASE=apache --build-arg TZ=${TIMEZONE} --target=prod .
18+
19+
tag:
20+
ifeq (${ZAP}, matched)
21+
docker tag kimai2/kimai:fpm-${KIMAI_VERSION}-prod kimai2/kimai:fpm
22+
docker tag kimai2/kimai:fpm-${KIMAI_VERSION}-dev kimai2/kimai:fpm-dev
23+
docker tag kimai2/kimai:apache-${KIMAI_VERSION}-prod kimai2/kimai:apache
24+
docker tag kimai2/kimai:apache-${KIMAI_VERSION}-dev kimai2/kimai:apache-dev
25+
docker tag kimai2/kimai:fpm-${KIMAI_VERSION}-prod kimai2/kimai:latest
26+
docker tag kimai2/kimai:apache-${KIMAI_VERSION}-dev kimai2/kimai:latest-dev
27+
else
28+
$(error ${KIMAI_VERSION} does not look like a release, x.y or x.y.z. Not tagging)
29+
endif
30+
31+
push:
32+
docker push kimai2/kimai:fpm-${KIMAI_VERSION}-dev
33+
docker push kimai2/kimai:fpm-${KIMAI_VERSION}-prod
34+
docker push kimai2/kimai:apache-${KIMAI_VERSION}-dev
35+
docker push kimai2/kimai:apache-${KIMAI_VERSION}-prod
36+
ifeq (${ZAP}, matched)
37+
docker push kimai2/kimai:kimai2/kimai:fpm-latest-prod
38+
docker push kimai2/kimai:kimai2/kimai:fpm-latest-dev
39+
docker push kimai2/kimai:kimai2/kimai:apache-latest-prod
40+
docker push kimai2/kimai:kimai2/kimai:apache-latest-dev
41+
docker push kimai2/kimai:kimai2/kimai:latest
42+
docker push kimai2/kimai:kimai2/kimai:latest-dev
43+
endif
44+
45+
clean-test:
46+
docker stop kimai-mysql-testing || true
47+
docker stop kimai-test-fpm-${KIMAI_VERSION}-prod || true
48+
docker stop kimai-test-fpm-${KIMAI_VERSION}-dev || true
49+
docker stop kimai-test-apache-${KIMAI_VERSION}-prod || true
50+
docker stop kimai-test-apache-${KIMAI_VERSION}-dev || true
51+
docker network rm kimai-test || true
52+
53+
test: clean-test
54+
docker network create --driver bridge kimai-test
55+
docker run --rm --network kimai-test --name kimai-mysql-testing -e MYSQL_DATABASE=kimai -e MYSQL_USER=kimai -e MYSQL_PASSWORD=kimai -e MYSQL_ROOT_PASSWORD=kimai -p 3399:3306 -d mysql
56+
docker run --rm --network kimai-test --name kimai-test-fpm-${KIMAI_VERSION}-prod -ti -e DATABASE_URL=mysql://kimai:kimai@kimai-mysql-testing:3306/kimai --entrypoint /self-test.sh kimai2/kimai:fpm-${KIMAI_VERSION}-prod
57+
docker run --rm --network kimai-test --name kimai-test-fpm-${KIMAI_VERSION}-dev -ti -e DATABASE_URL=mysql://kimai:kimai@kimai-mysql-testing:3306/kimai --entrypoint /self-test.sh kimai2/kimai:fpm-${KIMAI_VERSION}-dev
58+
docker run --rm --network kimai-test --name kimai-test-apache-${KIMAI_VERSION}-prod -ti -e DATABASE_URL=mysql://kimai:kimai@kimai-mysql-testing:3306/kimai --entrypoint /self-test.sh kimai2/kimai:apache-${KIMAI_VERSION}-prod
59+
docker run --rm --network kimai-test --name kimai-test-apache-${KIMAI_VERSION}-dev -ti -e DATABASE_URL=mysql://kimai:kimai@kimai-mysql-testing:3306/kimai --entrypoint /self-test.sh kimai2/kimai:apache-${KIMAI_VERSION}-dev
60+
61+
build-version: build test push
62+
63+
release: build test tag push

README.md

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,106 @@ The built images are available from [Kimai v2](https://hub.docker.com/repository
66

77
## Quick start
88

9-
Run the latest build against tbe master branch of the Kimai repo using a bundled DB. **This is not suitable for production use**:
9+
Run the latest production build:
1010

11-
docker run --rm -ti -p 8001:8001 --name kimai kimai/kimai2:latest-dev
11+
1. Start a DB
12+
13+
docker run --rm --name kimai-mysql-testing \
14+
-e MYSQL_DATABASE=kimai \
15+
-e MYSQL_USER=kimai \
16+
-e MYSQL_PASSWORD=kimai \
17+
-e MYSQL_ROOT_PASSWORD=kimai \
18+
-p 3399:3306 -d mysql
19+
20+
1. Start Kimai
21+
22+
docker run --rm --name kimai-test \
23+
-ti \
24+
-p 8001:8001 \
25+
-e DATABASE_URL=mysql://kimai:kimai@${HOSTNAME}:3399/kimai \
26+
kimai2/kimai:apache-latest-prod
27+
28+
1. Add a user, open a new terminal and:
29+
30+
docker exec -ti kimai-test \
31+
/opt/kimai/bin/console kimai:create-user admin admin@example.com ROLE_SUPER_ADMIN
32+
33+
You can now hit the kimai instance on http://localhost:8001
1234

13-
Create an admin user in the new running docker:
35+
This docker transient and will disappear when you stop the containers.
1436

15-
docker exec kimai /opt/kimai/bin/console kimai:create-user admin admin@example.com ROLE_SUPER_ADMIN
37+
docker stop kimai-mysql-testing kimai-test
1638

17-
This docker transient and will disappear when you stop the container.
39+
## Using docker-compose
1840

19-
## Documentation
41+
This will run the latest prod version using FPM with an nginx reverse proxy
2042

21-
[https://tobybatch.github.io/kimai2/](https://tobybatch.github.io/kimai2/)
43+
```docker-compose
44+
version: '3.5'
45+
services:
46+
47+
sqldb:
48+
image: mysql:5.7
49+
environment:
50+
- MYSQL_DATABASE=kimai
51+
- MYSQL_USER=kimaiuser
52+
- MYSQL_PASSWORD=kimaipassword
53+
- MYSQL_ROOT_PASSWORD=changemeplease
54+
#volumes: # Uncomment to persist data
55+
#- /var/lib/mysql
56+
command: --default-storage-engine innodb
57+
restart: unless-stopped
58+
healthcheck:
59+
test: mysqladmin -p$$MYSQL_ROOT_PASSWORD ping -h localhost
60+
interval: 20s
61+
start_period: 10s
62+
timeout: 10s
63+
retries: 3
64+
65+
nginx:
66+
image: tobybatch/nginx-fpm-reverse-proxy
67+
ports:
68+
- 8001:80
69+
volumes:
70+
- public:/opt/kimai/public:ro
71+
restart: unless-stopped
72+
depends_on:
73+
- kimai
74+
healthcheck:
75+
test: wget --spider http://nginx/health || exit 1
76+
interval: 20s
77+
start_period: 10s
78+
timeout: 10s
79+
retries: 3
80+
81+
kimai: # This is the latest FPM image of kimai
82+
image: kimai2/kimai:fpm-latest-prod
83+
environment:
84+
- APP_ENV=prod
85+
- TRUSTED_HOSTS=localhost
86+
- ADMINMAIL=admin@kimai.local
87+
- ADMINPASS=changemeplease
88+
- DATABASE_URL=mysql://kimaiuser:kimaipassword@sqldb/kimai
89+
- TRUSTED_HOSTS=nginx,localhost,127.0.0.1
90+
volumes:
91+
- public:/opt/kimai/public
92+
# - var:/opt/kimai/var
93+
# - ./ldap.conf:/etc/openldap/ldap.conf:z
94+
# - ./ROOT-CA.pem:/etc/ssl/certs/ROOT-CA.pem:z
95+
restart: unless-stopped
2296
23-
## Kimai Helm chart
97+
postfix:
98+
image: catatnight/postfix:latest
99+
environment:
100+
maildomain: neontribe.co.uk
101+
smtp_user: kimai:kimai
102+
restart: unless-stopped
24103
25-
There is also a Helm chart for easy deployment of Kimai on Kubernetes. See the [README](docs/helm/README.md) for more information.
104+
volumes:
105+
var:
106+
public:
107+
```
108+
109+
## Documentation
110+
111+
[https://tobybatch.github.io/kimai2/](https://tobybatch.github.io/kimai2/)

ROOT-CA.pem

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

assets/self-test.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
nohup /startup.sh 2>&1 & > /tmp/startup.log
4+
echo $$ > /tmp/startup.pid
5+
echo "Waiting for kimai to install"
6+
while [ ! -f /opt/kimai/var/installed ]; do
7+
echo -n ". "
8+
sleep 5
9+
done
10+
echo
11+
12+
# Test FPM CGI
13+
if [ -f /use_fpm ]; then
14+
15+
export SCRIPT_NAME=/opt/kimai/public/index.php
16+
export SCRIPT_FILENAME=/opt/kimai/public/index.php
17+
export REQUEST_METHOD=GET
18+
export SERVER_ADDR=localhost
19+
20+
COUNT=0
21+
until cgi-fcgi -bind -connect 127.0.0.1:9000 &> /dev/null
22+
do
23+
COUNT=$((COUNT+1))
24+
echo "Waiting for FPM Server to start (${COUNT})"
25+
sleep 3
26+
if [ "$COUNT" -gt 5 ]; then
27+
echo "FPM Failed to start."
28+
exit 1
29+
fi
30+
done
31+
32+
fi
33+
34+
# Test Apache/httpd
35+
if [ -f /use_apache ]; then
36+
37+
COUNT=0
38+
until curl -s -o /dev/null http://localhost:8001
39+
do
40+
COUNT=$((COUNT+1))
41+
echo "Waiting for Apache/HTTP to start (${COUNT})" &> /dev/null
42+
sleep 3
43+
if [ "$COUNT" -gt 5 ]; then
44+
echo "Apache/HTTP failed to start."
45+
exit 1
46+
fi
47+
done
48+
49+
fi
50+
51+
# Test PHP/Kimai
52+
/opt/kimai/bin/console kimai:version
53+
if [ $? != 0 ]; then
54+
echo "PHP/Kimai not responding"
55+
exit 1
56+
fi
57+
kill $(cat /tmp/startup.pid)
58+
59+

startup.sh renamed to assets/startup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function waitForDB() {
4444

4545
function handleStartup() {
4646
# first start?
47-
if ! [ -e /opt/kimai/installed ]; then
47+
if ! [ -e /opt/kimai/var/installed ]; then
4848
echo "first run - install kimai"
4949
/opt/kimai/bin/console -n kimai:install
5050
if [ ! -z "$ADMINPASS" ] && [ ! -a "$ADMINMAIL" ]; then
@@ -53,7 +53,7 @@ function handleStartup() {
5353
fi
5454
# Add this here so it's always available, it would be lost between conatiner restarts.
5555
export KIMAI=$(/opt/kimai/bin/console kimai:version --short)
56-
echo $KIMAI > /opt/kimai/installed
56+
echo $KIMAI > /opt/kimai/var/installed
5757
echo "Kimai2 ready"
5858
}
5959

File renamed without changes.

bin/copy-public.sh

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

0 commit comments

Comments
 (0)