Skip to content

Commit

Permalink
Merge pull request #11 from GoliathLabs/master
Browse files Browse the repository at this point in the history
feat: gh actions; improved deployment & update to latest version
  • Loading branch information
schinken authored Dec 4, 2023
2 parents 56142d4 + 72e7835 commit abd94fc
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .github/buildkitd.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[worker.oci]
max-parallelism = 4
51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build Docker image

on:
push:
branches:
- master
pull_request:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
with:
config: .github/buildkitd.toml
- name: Retrieve author data
run: |
echo AUTHOR=$(curl -sSL ${{ github.event.repository.owner.url }} | jq -r '.name') >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.authors=${{ env.AUTHOR }}
- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64
push: false
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.head_ref || github.ref_name }}
COMMIT=${{ github.sha }}
- name: Inspect Docker image
run: docker image inspect ${{ steps.meta.outputs.tags }}
59 changes: 59 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Publish Docker image
on:
push:
branches:
- master
tags:
- 'v*.*.*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
push_to_registry:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
config: .github/buildkitd.toml
- name: Login to DockerHub
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Retrieve author data
run: |
echo AUTHOR=$(curl -sSL ${{ github.event.repository.owner.url }} | jq -r '.name') >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.authors=${{ env.AUTHOR }}
- name: Build container image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64/v8,linux/arm/v7,linux/ppc64le,linux/s390x
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.head_ref || github.ref_name }}
COMMIT=${{ github.sha }}
40 changes: 21 additions & 19 deletions docker/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.8 as release
FROM alpine:3.18.3 as release

RUN apk --no-cache add ca-certificates \
&& apk --no-cache add \
Expand All @@ -7,47 +7,49 @@ RUN apk --no-cache add ca-certificates \

RUN mkdir /source
WORKDIR /source
RUN curl -Lo strichliste.tar.gz https://github.com/strichliste/strichliste/releases/download/v1.6.2/strichliste.tar.gz
RUN curl -Lo strichliste.tar.gz https://github.com/strichliste/strichliste/releases/download/v1.8.2/strichliste-v1.8.2.tar.gz
RUN tar -xf strichliste.tar.gz
RUN rm -r strichliste.tar.gz


FROM alpine:3.8
FROM alpine:3.18.3

RUN apk --no-cache add ca-certificates \
&& apk --no-cache add \
curl \
php7 \
php7-ctype \
php7-tokenizer \
php7-iconv \
php7-mbstring \
php7-xml \
php7-json \
php7-dom \
php7-pdo_mysql \
php7-fpm \
php81 \
php81-ctype \
php81-tokenizer \
php81-iconv \
php81-mbstring \
php81-xml \
php81-json \
php81-dom \
php81-pdo_mysql \
php81-fpm \
php81-session \
php81-sqlite3 \
php81-pdo_sqlite \
nginx \
bash \
mysql-client \
yarn

COPY --from=release /source source

COPY /docker/entrypoint.sh /source/entrypoint.sh
COPY entrypoint.sh /source/entrypoint.sh
RUN chmod +x /source/entrypoint.sh

RUN adduser -u 82 -D -S -G www-data www-data
RUN chown -R www-data:www-data /source
RUN chown -R www-data:www-data /var/lib/nginx
RUN chown -R www-data:www-data /var/tmp/nginx
RUN chown -R www-data:www-data /var/log/nginx
RUN chown -R www-data:www-data /var/log/php7
RUN chown -R www-data:www-data /var/log/php81

USER www-data

COPY ./config/php-fpm.conf /etc/php7/php-fpm.conf
COPY ./config/www.conf /etc/php7/php-fpm.d/www.conf
COPY ./config/php-fpm.conf /etc/php81/php-fpm.conf
COPY ./config/www.conf /etc/php81/php-fpm.d/www.conf
COPY ./config/nginx.conf /etc/nginx/nginx.conf
COPY ./config/default.conf /etc/nginx/conf.d/default.conf

Expand All @@ -57,4 +59,4 @@ WORKDIR /source/public
EXPOSE 8080

ENTRYPOINT ["/source/entrypoint.sh"]
CMD nginx && php-fpm7
CMD nginx && php-fpm81
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ The same change is necessary in config/default.conf:33 where the same DATABASE_U

### Setup initial database
After configuring the environment variables you can start the container by executing:
```docker-compose up -d```
```docker compose up -d```
After the containers are started you need to jump into the container by running the following command:
```docker-compose exec strichliste bash```
```docker compose exec strichliste bash```
Inside the container you need to run the following command to create the inital database schema:
```./../bin/console doctrine:schema:create```
(you might need to wait a bit for the database to start up, the command will tell you if it succeeded or not)
After creating the schema you can ```exit``` the container and the setup is done.

If you migrate from an older version of this repository you might need to rebuild the container to be able to use the new features:
```docker-compose up --build -d```
```docker compose up --build -d```

As default the service is running on localhost:8080

## Traefik configuration
To use traefik (https://traefik.io/) the docker-compose file has comments for the necessary configuration which should make it easy to setup.
To use traefik (https://traefik.io/) the docker compose file has comments for the necessary configuration which should make it easy to setup.

## Migrating data from <= 1.4.1 to a newer version
To migrate your data from the old sqlite database to the new MariaDB you need a few manual steps. This is probably not the best/most elegant solution but it worked for my production environment.
Expand All @@ -52,7 +52,7 @@ In this moment make sure the amount of columns in the file matches the first lin

### Mount the files into the container
To make the csv files accessible from inside the container we need to mount them as volumes.
To do that you would add the following line for each of the 3 files to the volumes section inside the docker-compose.yml under the service strichliste (line 22):
To do that you would add the following line for each of the 3 files to the volumes section inside the docker compose.yml under the service strichliste (line 22):
```- ./path/to/csv/file.csv:/source/var/file.csv```

### Start the container, connect to it and setup inital database schema
Expand Down
2 changes: 1 addition & 1 deletion config/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ server {

# set DATABASE_URL env Variable

fastcgi_param DATABASE_URL "mysql://strichliste:{user_pwd}@strichliste_db/strichliste";
fastcgi_param DATABASE_URL "mysql://strichliste:{user_pwd}@strichliste-db/strichliste";
}

# return 404 for all other php files not matching the front controller
Expand Down
6 changes: 5 additions & 1 deletion config/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: 'mariadb-10.4.6'
server_version: 'mariadb-10.11.5'
charset: utf8mb4
default_table_options:
charset: utf8mb4
Expand All @@ -20,6 +20,10 @@ doctrine:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
datetime_functions:
date: App\Doctrine\Functions\Date
iif: App\Doctrine\Functions\Iif
mappings:
App:
is_bundle: false
Expand Down
4 changes: 2 additions & 2 deletions config/php-fpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
daemonize = no

; pool definition aka www
include=/etc/php7/php-fpm.d/*.conf
include=/etc/php7/conf.d/
include=/etc/php81/php-fpm.d/*.conf
include=/etc/php81/conf.d/
9 changes: 4 additions & 5 deletions config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

imports:
- { resource: 'strichliste.yaml' }


# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
Expand All @@ -17,6 +17,8 @@ services:
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
bind:
$strichlisteSettings: '%strichliste%'

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
Expand All @@ -30,8 +32,5 @@ services:
resource: '../src/Controller'
tags: ['controller.service_arguments']

App\EventListener\ApiExceptionListener:
tags:
- { name: kernel.event_listener, event: kernel.exception }
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
# please note that last definitions always *replace* previous ones
21 changes: 14 additions & 7 deletions config/strichliste.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
parameters:
strichliste:

article:
enabled: true
autoOpen: false

common:
idleTimeout: 30000 # Time in ms

paypal:
enabled: false
recipient: "foo@bar.com"
recipient: "foo@bar.de"
fee: 0

user:
Expand Down Expand Up @@ -31,12 +39,15 @@ parameters:
timeout: '5 minute' # See http://de.php.net/manual/en/datetime.formats.relative.php

boundary:
upper: 200000
lower: -200000
upper: 15000
lower: -2000

transactions:
enabled: true

splitInvoice:
enabled: true

deposit:
enabled: true
custom: true
Expand All @@ -46,8 +57,6 @@ parameters:
- 200
- 500
- 1000
- 1500
- 2000

dispense:
enabled: true
Expand All @@ -58,5 +67,3 @@ parameters:
- 200
- 500
- 1000
- 1500

20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
version: "2"
version: "3.8"

networks:
db_net:
external: false
services:
strichliste:
image: ghcr.io/strichliste/strichliste-docker:master
build:
context: .
dockerfile: ./docker/Dockerfile
# if you use traefik you can remove the ports section
ports:
- 8080:8080
networks:
# - traefik_network # your traefik network
# - proxy # your traefik network
- default
- db_net
env_file:
- docker.env
volumes:
Expand All @@ -31,12 +27,16 @@ services:
# - "traefik.frontend.rule=Host:{URL}"
# - "traefik.enable=true"
# - "traefik.port=8080"
strichliste_db:
image: mariadb:10.4.6
strichliste-db:
image: mariadb:10.11.5
restart: always
networks:
- db_net
- default
env_file:
- docker.env
volumes:
- ./data/mysql:/var/lib/mysql

networks:
proxy:
external: true
Loading

0 comments on commit abd94fc

Please sign in to comment.