Browse Source

Initial commit

enhancement/kaniko
James Harmison 2 months ago
commit
2be7e42871
Signed by: jharmison GPG Key ID: 32383B2D27A5D4B5
15 changed files with 434 additions and 0 deletions
  1. +5
    -0
      .gitignore
  2. +65
    -0
      Dockerfile
  3. +150
    -0
      build.sh
  4. +39
    -0
      docker-compose.yml
  5. +5
    -0
      env/db.env.example
  6. +8
    -0
      env/run.env.example
  7. +31
    -0
      podman/automatic.sh
  8. +13
    -0
      podman/clean.sh
  9. +21
    -0
      podman/common.sh
  10. +8
    -0
      podman/start.sh
  11. +8
    -0
      podman/stop.sh
  12. +43
    -0
      root/usr/local/bin/entrypoint.sh
  13. +28
    -0
      root/var/www/html/.env
  14. +7
    -0
      root/var/www/html/config/trustedproxy.php
  15. +3
    -0
      root/var/www/html/setup.env

+ 5
- 0
.gitignore View File

@ -0,0 +1,5 @@
db.env
run.env
tags
*.swp

+ 65
- 0
Dockerfile View File

@ -0,0 +1,65 @@
FROM php:7.4-apache
ARG AKAUNTING_DOCKERFILE_VERSION=0.1
ARG GIT_BRANCH=undefined
ARG GIT_COMMIT=undefined
ARG BUILD_DATE=undefined
LABEL maintainer="James Harmison <jharmison@gmail.com>" \
com.jharmison.akaunting.dockerfile.version=$AKAUNTING_DOCKERFILE_VERSION \
com.jharmison.akaunting.branch=$GIT_BRANCH \
com.jharmison.akaunting.commit=$GIT_COMMIT \
com.jharmison.akaunting.build-date=$BUILD_DATE
RUN apt-get update \
&& apt-get -y upgrade --no-install-recommends \
&& apt-get install -y \
build-essential \
imagemagick \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libjpeg-dev \
libmcrypt-dev \
libonig-dev \
libpng-dev \
libpq-dev \
libssl-dev \
libxml2-dev \
libxrender1 \
libzip-dev \
locales \
openssl \
unzip \
zip \
zlib1g-dev \
--no-install-recommends \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
&& cp /usr/share/i18n/SUPPORTED /etc/locale.gen \
&& locale-gen
RUN docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
&& docker-php-ext-install -j$(nproc) \
gd \
bcmath \
intl \
mbstring \
pcntl \
pdo \
pdo_mysql \
zip
RUN mkdir -p /var/www/akaunting \
&& curl -Lo /tmp/akaunting.zip 'https://akaunting.com/download.php?version=latest&utm_source=docker&utm_campaign=developers' \
&& unzip /tmp/akaunting.zip -d /var/www/html \
&& rm -f /tmp/akaunting.zip
COPY root/* /
EXPOSE 80
ENTRYPOINT ["/usr/local/bin/akaunting.sh"]
CMD ["--start"]

+ 150
- 0
build.sh View File

@ -0,0 +1,150 @@
#!/bin/bash -e
cd "$(dirname "$(realpath "$0")")"
if command -v podman &>/dev/null; then
export BUILDAH_FORMAT=docker
runtime=podman
elif command -v docker &>/dev/null; then
if ! docker ps &>/dev/null; then
echo "No privileges with Docker." >&2
exit 1
fi
runtime=docker
else
echo "No container runtime detected." >&2
exit 2
fi
DEFAULT_REGISTRY=harbor.jharmison.com
DEFAULT_REPOSITORY=akaunting
DEFAULT_IMAGE=akaunting
print_usage() {
prog=$(basename $0)
echo "usage: $prog [-h|--help] | [-r|--registry REGISTRY] [-R|--repository REPO]"
echo " [-i|--image IMAGE] [-b|--build-tag TAG] [-t|--tag TAG] [-d|--dev] [-p|--publish]"
}
print_help() {
print_usage
cat << EOF
OPTIONS:
-h|--help Print this help page and exit
-r|--registry Set the registry to use (default: $DEFAULT_REGISTRY)
-R|--repostory Set the repository to use (default: $DEFAULT_REPOSITORY)
-i|--image Set the image name to use (default: $DEFAULT_IMAGE)
-b|--build-tag Set the default tag name to use (default: <git branch>)
-t|--tag Additional tags for image (default: [latest])
-d|--dev Append every tag built with "-dev"
-p|--publish Push all built tags
EXAMPLES:
# To build only tag :dev
$prog -b dev -t "" # note that \`-t ""\` is required to not tag latest
# To build this branch and push to the default registry/repo/image:tag
$prog -p
# To build a development release without overwriting the release image
$prog -d
# note that for convenience, you can assume this to build :latest-dev
# To build and push to a local docker v2 registry
$prog --registry localhost:5000 --publish
# To build, including a tag for the version of Akaunting
akaunting_release=\$(curl -sH "Accept: application/vnd.github.v3+json" \\
https://api.github.com/repos/akaunting/akaunting/releases/latest \\
| jq -r '.tag_name')
$prog --tag \$akaunting_release
# note that this will _NOT_ tag :latest
EOF
}
tags=()
registry=""
repository=""
image=""
build_tag=""
tag_suffix=""
do_push=""
while [ $# -gt 0 ]; do
case "$1" in
-r|--registry)
shift
registry="$1"
;;
-R|--repository)
shift
repository="$1"
;;
-i|--image)
shift
image="$1"
;;
-b|--build-tag)
shift
build_tag="$1"
;;
-t|--tag)
shift
tags+=("$1")
;;
-d|--dev)
tag_suffix="-dev"
;;
-p|--publish)
do_push=true
;;
-h|--help)
print_help
exit 0
;;
*)
print_usage >&2
exit 1
;;
esac; shift
done
this_branch=$(git branch --show-current) || this_branch=none
this_commit=$(git rev-parse HEAD) || this_commit=unknown
build_date=$(date -Iseconds)
registry="${registry:-$DEFAULT_REGISTRY}"
repository="${repository:-$DEFAULT_REPOSITORY}"
image="${image:-$DEFAULT_IMAGE}"
build_tag="${build_tag:-$this_branch}"
if [ ${#tags[@]} -eq 0 ]; then
tags=(latest)
fi
akaunting_build_img="${registry}/${repository}/${image}"
akaunting_build_tag="${akaunting_build_img}:${build_tag}${tag_suffix}"
if [ "$do_push" ]; then
$runtime login "$registry"
fi
$runtime build \
--build-arg BUILD_DATE="$build_date" \
--build-arg GIT_BRANCH="$this_branch" \
--build-arg GIT_COMMIT="$this_commit" \
. -t "$akaunting_build_tag"
if [ "$do_push" ]; then
$runtime push "$akaunting_build_tag"
fi
for tag in "${tags[@]}"; do
if [ "$tag" ]; then
new_tag="${akaunting_build_img}:${tag}${tag_suffix}"
$runtime tag "$akaunting_build_tag" "$new_tag"
if [ "$do_push" ]; then
$runtime push "$new_tag"
fi
fi
done

+ 39
- 0
docker-compose.yml View File

@ -0,0 +1,39 @@
version: '3.7'
services:
akaunting:
image: harbor.jharmison.com/akaunting/akaunting
build:
context: .
args:
- GIT_BRANCH
- GIT_COMMIT
- BUILD_DATE
ports:
- 8080:80
volumes:
- akaunting-data:/var/www/html/storage
restart: unless-stopped
env_file:
- env/run.env
environment:
- AKAUNTING_SETUP
akaunting-db:
image: mariadb
volumes:
- akaunting-db:/var/lib/mysql
restart: unless-stopped
env_file:
- env/db.env
akaunting-update:
image: containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: --cleanup akaunting akaunting-db
volumes:
akaunting-data:
akaunting-db:

+ 5
- 0
env/db.env.example View File

@ -0,0 +1,5 @@
MYSQL_DATABASE=akaunting_db # This could be changed
MYSQL_USER=akaunting_admin # This could be changed
MYSQL_PASSWORD=akaunting_password # This should definitely be changed to something long and random
MYSQL_RANDOM_ROOT_PASSWORD=yes # You should probably leave this

+ 8
- 0
env/run.env.example View File

@ -0,0 +1,8 @@
APP_URL=https://akaunting.example.com # You should change this to match your reverse proxy DNS name
DB_HOST=akaunting-db # You should change this to the appropriate hostname, if needed
DB_DATABASE=akaunting_db # You should change this to match env/db.env
DB_USERNAME=akaunting_admin # You should change this to match env/db.env
DB_PASSWORD=akaunting_password # You should change this to match env/db.env
DB_PREFIX=asd_ # You should change this to a random string of three numbers or letters followed by an underscore

+ 31
- 0
podman/automatic.sh View File

@ -0,0 +1,31 @@
#!/bin/bash -ex
cd "$(dirname "$(realpath "$0")")"
. common.sh
user_do() {
sudo -u $user "${@}"
}
# linger is required for user session to start w/ systemd
sudo loginctl enable-linger $user
user_do podman volume create $db_vol
user_do podman volume create $vol
user_do podman pull $db_img
user_do podman pull $img
user_do podman create -v $db_vol:/var/lib/mysql:Z "${extra_labels[@]}" -p $db_port:80 --env-file $db_env --name $db_name $db_img
user_do podman create -v $vol:/var/www/html/storage:Z "${extra_labels[@]}" -p $port:80 --env-file $run_env --name $name $img
user_systemd_dir=$(user_do /bin/bash -lic 'echo $HOME' 2>/dev/null)/.config/systemd/user
user_do mkdir -p "$user_systemd_dir"
user_do podman generate systemd --new --name $db_name > "$user_systemd_dir/$db_name.service"
user_do podman generate systemd --new --name $name > "$user_systemd_dir/$name.service"
user_do systemctl --user daemon-reload
user_do systemctl --user enable $db_name.service $name.service --now
user_do systemctl --user enable podman-auto-update.timer

+ 13
- 0
podman/clean.sh View File

@ -0,0 +1,13 @@
#!/bin/bash -x
cd "$(dirname "$(realpath "$0")")"
. common.sh
./stop.sh
podman rm $name
podman rm $db_name
podman volume rm $vol
podman volume rm $db_vol

+ 21
- 0
podman/common.sh View File

@ -0,0 +1,21 @@
#!/bin/bash
img=${AKAUNTING_IMAGE:-harbor.jharmison.com/akaunting/akaunting:latest}
db_img=${AKAUNTING_DB_IMAGE:-docker.io/library/mariadb:latest}
name=${AKAUNTING_NAME:-akaunting}
db_name=${AKAUNTING_DB_NAME:-akaunting-db}
vol=${AKAUNTING_VOLUME:-akaunting-data}
db_vol=${AKAUNTING_DB_VOLUME:-akaunting-db}
port=${AKAUNTING_PORT:-8080}
db_port=${AKAUNTING_DB_PORT:-3306}
run_env=${AKAUNTING_RUN_ENV_FILE:-../env/run.env}
db_env=${AKAUNTING_DB_ENV_FILE:-../env/db.env}
if [ "${AKAUNTING_AUTO_UPDATE:-true}" ]; then
extra_labels=(--label io.containers.autoupdate=image)
else
extra_labels=()
fi
user=${AKAUNTING_AUTOMATIC_USER:-$USER}

+ 8
- 0
podman/start.sh View File

@ -0,0 +1,8 @@
#!/bin/bash -ex
cd "$(dirname "$(realpath "$0")")"
. common.sh
podman run -v $db_vol:/var/lib/mysql --env-file $db_env -p $db_port:3306 -d --rm --name $db_name $db_img
podman run -v $vol:/var/www/html/storage --env-file $run_env -p $port:80 -d --rm --name $name $img "${@}"

+ 8
- 0
podman/stop.sh View File

@ -0,0 +1,8 @@
#!/bin/bash -x
cd "$(dirname "$(realpath "$0")")"
. common.sh
podman stop $name
podman stop $db_name

+ 43
- 0
root/usr/local/bin/entrypoint.sh View File

@ -0,0 +1,43 @@
#!/bin/bash -e
a2enmod rewrite
do_start=
do_shell=
do_setup=
while [ $# -gt 0 ]; do
case "$1" in
--start)
do_start=true
;;
--shell)
do_start=false
do_shell=true
;;
--setup)
do_setup=true
do_start=true
;;
esac
shift
done
if [ "$do_setup" -o "$AKAUNTING_SETUP" == "true" ]; then
mv setup.env .env
unset APP_INSTALLED
unset APP_DEBUG
fi
mkdir -p storage/framework/{sessions,views,cache}
mkdir -p storage/app/uploads
chmod -R u=rwX,g=rX,o=rX /var/www/html
chown -R www-data:root /var/www/html
if [ "$do_start" ]; then
exec docker-php-entrypoint apache2-foreground
elif [ "$do_shell" ]; then
exec /bin/bash -li
fi

+ 28
- 0
root/var/www/html/.env View File

@ -0,0 +1,28 @@
PP_NAME=Akaunting
APP_ENV=production
APP_LOCALE=en-US
APP_INSTALLED=true
APP_DEBUG=false
DB_CONNECTION=mysql
DB_PORT=3306
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_CONNECTION=sync
LOG_CHANNEL=stderr
MAIL_MAILER=mail
MAIL_HOST=localhost
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_NAME=null
MAIL_FROM_ADDRESS=null
FIREWALL_ENABLED=true
MODEL_CACHE_ENABLED=true

+ 7
- 0
root/var/www/html/config/trustedproxy.php View File

@ -0,0 +1,7 @@
<?php
return [
'proxies' => '*',
'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_ALL,
];

+ 3
- 0
root/var/www/html/setup.env View File

@ -0,0 +1,3 @@
LOG_CHANNEL=stderr
APP_LOCALE=en-US

Loading…
Cancel
Save