Initial dockerfile to build a LedgerSMB image

This commit is contained in:
John Locke 2015-07-05 00:54:16 -07:00
parent 98409e39f4
commit 3a5553d593
4 changed files with 214 additions and 1 deletions

69
Dockerfile Normal file
View File

@ -0,0 +1,69 @@
FROM debian:jessie
MAINTAINER Freelock john@freelock.com
# Build time variables
ENV LSMB_VERSION 1.4
# Install PHP5 and modules along with composer binary
RUN DEBIAN_FRONTENT=noninteractive && \
apt-get update && apt-get -y install \
git \
libdatetime-perl libdbi-perl libdbd-pg-perl \
libcgi-simple-perl libtemplate-perl libmime-lite-perl \
liblocale-maketext-lexicon-perl libtest-exception-perl \
libtest-trap-perl liblog-log4perl-perl libmath-bigint-gmp-perl \
libfile-mimeinfo-perl libtemplate-plugin-number-format-perl \
libdatetime-format-strptime-perl libconfig-general-perl \
libdatetime-format-strptime-perl libio-stringy-perl libmoose-perl \
libconfig-inifiles-perl libnamespace-autoclean-perl \
libcarp-always-perl libjson-perl \
libtemplate-plugin-latex-perl texlive-latex-recommended \
libnet-tclink-perl \
libxml-twig-perl \
starman \
postgresql-client-9.4 \
ssmtp
# Install LedgerSMB
RUN cd /srv && \
git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb
WORKDIR /srv/ledgersmb
RUN git checkout $LSMB_VERSION
#RUN sed -i \
# -e "s/short_open_tag = Off/short_open_tag = On/g" \
# -e "s/post_max_size = 8M/post_max_size = 20M/g" \
# -e "s!^;sendmail_path =.*\$!sendmail_path = /usr/sbin/ssmtp -t!g" \
# /etc/php5/fpm/php.ini && \
# Configure outgoing mail to use host, other run time variable defaults
## sSMTP
ENV SSMTP_ROOT ar@example.com
ENV SSMTP_MAILHUB 172.17.42.1
ENV SSMTP_HOSTNAME 172.17.42.1
#ENV SSMTP_USE_STARTTLS
#ENV SSMTP_AUTH_USER
#ENV SSMTP_AUTH_PASS
ENV SSMTP_FROMLINE_OVERRIDE YES
#ENV SSMTP_AUTH_METHOD
ENV POSTGRES_HOST postgres
COPY start.sh /usr/bin/start.sh
COPY update_ssmtp.sh /usr/bin/update_ssmtp.sh
RUN chown www-data /etc/ssmtp /etc/ssmtp/ssmtp.conf && \
chmod +x /usr/bin/update_ssmtp.sh /usr/bin/start.sh && \
mkdir -p /var/www
# Internal Port Expose
EXPOSE 5000
#USER www-data
CMD ["start.sh"]

107
README.md
View File

@ -1,2 +1,107 @@
# ledgersmb-docker
# ledgersmb-docker - EXPERIMENTAL
Dockerfile for LedgerSMB Docker image
This is a work in progress to make a docker image for running LedgerSMB. It should not be relied upon for production use!
# Supported tags and respective `Dockerfile` links
- `1.5`, `dev-master` - Master branch, unstable
- `1.4`, `latest` - Tip of git 1.4 branch
- `1.4.12` - Latest stable release (not yet built)
- `1.3.45` - Last 1.3.x release (not yet built)
# What is LedgerSMB?
The LedgerSMB project's priority is to provide an extremely capable yet user-friendly accounting and ERP solution to small to mid-size businesses in all locales where there is interest in using the software. The focus on small to mid-size businesses offers an opportunity to provide a positive user experience in ways which are not present in larger organizations. LedgerSMB ought to strive to be both the ideal SMB accounting/ERP package and also a solution that a start-up will never outgrow. The goals mentioned above will help us provide this ideal solution by allowing us to focus both on technical architecture and on user experience.
# How is this image designed to be used?
This Docker image is built to provide a self-contained LedgerSMB instance. To be functional, you need to connect it to a running Postgres installation. The official Postgres container will work as is, if you link it to the LedgerSMB instance at startup, or you can provide environment variables to an appropriate Postgres server.
LedgerSMB provides an http interface built on Starman out of the box, listening on port 5000. We do not recommend exposing this port, because we strongly recommend encrypting all connections using SSL/TLS. For production use, we recommend running a web server configured with SSL, such as Nginx or Apache, and proxying connections to LedgerSMB.
The other services you will need to put this in production are an SMTP gateway (set environment variables for SSMTP at container startup) and optionally a local print server (e.g. CUPS) installation. The print service is not currently supported in this Docker image, but pull requests are welcomed ;-)
# How to use this image
## Start a postgres instance
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
This image includes `EXPOSE 5432` (the postgres port), so standard container linking will make it automatically available to the linked containers. The default `postgres` user and database are created in the entrypoint with `initdb`.
> The postgres database is a default database meant for use by users, utilities and third party applications.
> [postgresql.org/docs](http://www.postgresql.org/docs/9.3/interactive/app-initdb.html)
## Start LedgerSMB
docker run --name myledger --link some-postgres:postgres -d ledgersmb/ledgersmb
## Set up LedgerSMB
Visit http://myledger:5000/setup.pl (you can forward port 5000 to the host machine, or lookup the IP address for the "myledger" container if running on localhost)
Log in with the "postgres" user and the password you set when starting up the Postgres container.
Once you have completed the setup, you have a fully functional LedgerSMB instance running!
## Updating the LedgerSMB container
No persistant data is stored in the LedgerSMB container. All LedgerSMB data is stored in Postgres, so you can stop/destroy/run a new LedgerSMB container, and as long as you link it to the Postgres database, you should be able to pick up where you left off.
## Environment Variables
The LedgerSMB image uses several environment variables which are easy to miss. While none of the variables are required, they may significantly aid you in using the image.
### `POSTGRES_HOST` = 'postgres'
This environment variable is used to specify the hostname of the Postgres server. The default is "postgres", which will find the container linked in.
If you set this to another hostname, LedgerSMB will attempt to connect to that hostname instead.
### `SSMTP_ROOT` `SSMTP_MAILHUB` `SSMTP_HOSTNAME` `SSMTP_USE_STARTTLS` `SSMTP_AUTH_USER` `SSMTP_AUTH_PASS` `SSMTP_METHOD` `SSMTP_FROMLINE_OVERRIDE`
These variables are used to set outgoing SMTP defaults. To set the outgoing email address, set SSMTP_ROOT, and SSMTP_HOSTNAME at a minimum -- SSMTP_MAILHUB defaults to the default docker0 interface, so if your host is already configured to relay mail, this should relay successfully with only those two set.
Use the other environment variables to relay mail through another host.
### `CREATE_DATABASE` `POSTGRES_PASS`
If `CREATE_DATABASE` is set, the tools/dbsetup.pl is called with the database name, and the postgres host and password. Currently this is failing with 'Can't locate object method "process_roles" via package "LedgerSMB::Database" at tools/dbsetup.pl line 203.'
Once this is working, this will provision a new database in the existing server. After the first run, we recommend stopping/removing the LedgerSMB container and starting a new one without these variables -- the previous database should remain present.
# Troubleshooting/Developing
You can connect to a running container using:
> docker exec -ti myledger /bin/bash
... this will give you a shell inside the container where you can inspect/troubleshoot the installation.
Currently the LedgerSMB installation is in /srv/ledgersmb, and the startup/config script is /usr/bin/start.sh.
# Supported Docker versions
This image is officially supported on Docker version 1.7.0.
Support for older versions is provided on a best-effort basis.
# User Feedback
## Documentation
This is a brand new effort, and we will be adding documentation to the http://ledgersmb.org site when we get a chance.
## Issues
If you have any problems with or questions about this image or LedgerSMB, please contact us on the [mailing list](http://ledgersmb.org/topic/support/mailing-lists-rss-and-nntp-feeds) or through a [GitHub issue](https://github.com/ledgersmb/ledgersmb-docker/issues).
You can also reach some of the official LedgerSMB maintainers via the `#ledgersmb` IRC channel on [Freenode](https://freenode.net).
## Contributing
You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.

27
start.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
if [[ -e /tmp/smtpconfig ]]; then
echo "smtp configured."
else
update_ssmtp.sh
touch /tmp/smtpconfig
fi
if [[ ! -f ledgersmb.conf ]]; then
cp ledgersmb.conf.default ledgersmb.conf
sed -i \
-e "s/\(cache_templates = \).*\$/cache_templates = 1/g" \
-e "s/\(host = \).*\$/\1$POSTGRES_HOST/g" \
-e "s%\(sendmail = \).*%\1/usr/bin/ssmtp%g" \
/srv/ledgersmb/ledgersmb.conf
fi
if [ ! -z ${CREATE_DATABASE+x} ]; then
perl tools/dbsetup.pl --company $CREATE_DATABASE \
--host $POSTGRES_HOST \
--postgres_password "$POSTGRES_PASS"
fi
# start ledgersmb
exec starman tools/starman.psgi

12
update_ssmtp.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
sed -i \
-e "s/\(root=\).*\$/\1$SSMTP_ROOT/g" \
-e "s/\(mailhub=\).*\$/\1$SSMTP_MAILHUB/g" \
-e "s/\(hostname=\).*\$/\1$SSMTP_HOSTNAME/g" \
/etc/ssmtp/ssmtp.conf
[ -z "$SSMTP_USE_STARTTLS" ] || echo "UseSTARTTLS=$SSMTP_USE_STARTTLS" >> /etc/ssmtp/ssmtp.conf
[ -z "$SSMTP_AUTH_USER" ] || echo "AuthUser=$SSMTP_AUTH_USER" >> /etc/ssmtp/ssmtp.conf
[ -z "$SSMTP_AUTH_PASS" ] || echo "AuthPass=$SSMTP_AUTH_PASS" >> /etc/ssmtp/ssmtp.conf
[ -z "$SSMTP_AUTH_METHOD" ] || echo "AuthMethod=$SSMTP_AUTH_METHOD" >> /etc/ssmtp/ssmtp.conf
[ -z "$SSMTP_FROMLINE_OVERRIDE" ] || echo "FromLineOverride=$SSMTP_FROMLINE_OVERRIDE" >> /etc/ssmtp/ssmtp.conf