-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a Dockerfile to ease development #66
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,7 @@ working on new features, please reach out to us first and discuss your feature | |
idea. Once a feature has been discussed and the general concept agreed to, a | ||
feature issue can be opened to work on the details of the implementation. | ||
|
||
For practical details and guides for developing the pgeu-system, please consult | ||
the file [tools/devsetup/README.txt](tools/devsetup/README.txt) | ||
|
||
The mailing list for discussing pgeu-system is <[email protected]>. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Download base image Debian Buster as the biggest installations run there | ||
FROM debian:buster-slim | ||
|
||
# LABEL the image | ||
LABEL maintainer="[email protected]" | ||
LABEL version="0.1" | ||
LABEL description="This is a base development environment for the \ | ||
PostgreSQL Europe Conference Management System" | ||
|
||
# Arguments to create user for file mounting | ||
ARG USER_ID | ||
ARG GROUP_ID | ||
|
||
# Avoid interactive packages | ||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
# Update to the latest version and install basic packages | ||
RUN apt-get update && apt-get -y install apt-utils | ||
RUN apt-get update && apt-get -y install wget \ | ||
sudo \ | ||
apt-utils \ | ||
gnupg gnupg1 gnupg2 \ | ||
lsb-release | ||
|
||
# Install postgres, start with the required repo | ||
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc > /tmp/key | ||
RUN sudo apt-key add /tmp/key | ||
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list | ||
|
||
# Update again and install postgres | ||
RUN apt-get update && apt-get install -y \ | ||
postgresql-13 \ | ||
postgresql-client-13 \ | ||
postgresql-server-dev-13 | ||
|
||
# Make it part of the path | ||
ENV PATH="/usr/lib/postgresql/13/bin:${PATH}" | ||
|
||
# Install the rest of the essential packages | ||
RUN apt-get update && apt-get install -y \ | ||
python3.7 \ | ||
virtualenv \ | ||
python3-virtualenv \ | ||
build-essential \ | ||
python-dev \ | ||
libffi-dev \ | ||
libssl-dev \ | ||
libjpeg-dev \ | ||
libpng-dev \ | ||
libqrencode-dev \ | ||
uwsgi \ | ||
uwsgi-plugin-python3 \ | ||
python3-pip \ | ||
python3-cairosvg \ | ||
python3-qrencode \ | ||
ttf-dejavu | ||
|
||
# Create the user to be used with bash for interactive sessions | ||
RUN addgroup --gid $GROUP_ID pgeusystem | ||
RUN useradd -s /bin/bash --gid $GROUP_ID -G sudo,postgres,root --uid $USER_ID pgeusystem | ||
|
||
# Create the directories to be used and adjust the ownership | ||
WORKDIR /opt/pgeusystem/setup | ||
WORKDIR /opt/pgeusystem/pgdata | ||
WORKDIR /opt/pgeusystem/app | ||
RUN chown -R pgeusystem.pgeusystem /opt/pgeusystem | ||
|
||
# Create the datadir, db and user for out app | ||
USER pgeusystem | ||
RUN pg_ctl -D /opt/pgeusystem/pgdata initdb | ||
RUN pg_ctl -D /opt/pgeusystem/pgdata -l /opt/pgeusystem/pgdata/logfile start \ | ||
&& psql -c 'CREATE DATABASE pgeusystem' postgres \ | ||
&& psql -c 'GRANT ALL PRIVILEGES ON DATABASE pgeusystem TO pgeusystem' pgeusystem \ | ||
&& pg_ctl -D /opt/pgeusystem/pgdata stop | ||
|
||
# Create a file to run the app, expects that the volume is mounted | ||
WORKDIR /opt/pgeusystem/setup | ||
USER pgeusystem | ||
RUN echo "#!/bin/bash\n\ | ||
set -e\n\ | ||
pg_ctl -D /opt/pgeusystem/pgdata -l /opt/pgeusystem/pgdata/logfile start\n\ | ||
pushd /opt/pgeusystem/app/\n\ | ||
./tools/devsetup/dev_setup.sh localhost 5432 pgeusystem pgeusystem\n\ | ||
uwsgi --ini ./devserver-uwsgi.ini\n" > startup.sh | ||
RUN chmod +x startup.sh | ||
|
||
# Set the workdirectory | ||
WORKDIR /opt/pgeusystem/app | ||
|
||
CMD ["../setup/startup.sh"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,43 @@ macOS support | |
------------- | ||
All required dependencies except virtualenv can be installed via Homebrew, | ||
virtualenv is installed with pip. | ||
|
||
|
||
Dockerfile | ||
---------- | ||
|
||
A Dockerfile is present to showcase the needed installation and how to run the | ||
app. The base image is based on debian buster, which can also be used for | ||
development should one wishes to. The admin name for the app and the database, | ||
as well as the name of the database itself is set to 'pgeusystem'. | ||
|
||
The created user, pgeusystem, can be mapped to the userid and groupid of the | ||
host user that owns the base directory that the app is installed. It is | ||
recommended that it is not root. That allows for the base directory to be | ||
mounted in the container and changes to be able to propagate from host to | ||
container without rebuilding the image. | ||
|
||
A typical usecase would be to build the docker image, via: | ||
$ docker build -t pgeusystem-image \ | ||
--build-arg USER_ID=$(id -u) \ | ||
--build-arg GROUP_ID=$(id -g) \ | ||
-f ./tools/devsetup/Dockerfile . | ||
from the base directory. | ||
|
||
Then run said image in the background using the host's network and binding the | ||
base directory in shared mode, via: | ||
$ docker run \ | ||
--mount type=bind,source="$(pwd)",target=/opt/pgeusystem/app,bind-propagation=shared \ | ||
--name pgeusystem-image \ | ||
--network host \ | ||
-d \ | ||
pgeusystem-image | ||
|
||
If the above commands are successfull then one can reach the index page of the | ||
app in http://localhost:8012 | ||
|
||
If the user so wishes, can reach the database in the running container via: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that mean you have to login into the container first? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest above to run the image with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, perfect. |
||
$ psql -h localhost -U pgeusystem pgeusystem | ||
|
||
Finally to stop the running image from running, issue: | ||
$ docker container stop pgeusystem-image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My inner monk is confused by the missing spaces here ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused by your confusion. Sorry, which missing spaces are you referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spaces before "./tools", which are fewer than the other ones. But that's just eye candy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Will fix :)