Skip to content
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

Added fully configured Docker image #83

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/.settings
/.project
/.buildpath
/.composer
/.idea
/satis.phar
/vendor
/satis.json
/web/packages.json
/web/include
/web/dist
!/web/robots.txt
/config.yml
/cache/*
/logs/*
/satis/*
/database.sqlite
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.project
/.buildpath
/.composer
/.idea
/satis.phar
/vendor
/satis.json
Expand Down
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM composer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Composer is already included in webdevops/php-nginx:7.2 and updated on every image build.


FROM webdevops/php-nginx:7.2

ENV WEB_DOCUMENT_ROOT=/app/web
ENV COMPOSER_ALLOW_SUPERUSER 1

ENV PACKAGES_NAME='Terramar Labs'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the amount of image layers as small as possible, you should use:

ENV FOO='Bar' \
         BAR='Baz'

ENV PACKAGES_HOMEPAGE='https://github.com/terramar-labs/packages'
ENV PACKAGES_CONTACT='[email protected]'
ENV PACKAGES_BASEPATH='https://localhost'
ENV PACKAGES_SECURE=false
ENV PACKAGES_USER=user
ENV PACKAGES_PASSWORD=password
ENV PACKAGES_PDO_DRIVER=pdo_sqlite
ENV PACKAGES_PDO_PATH=%app.root_dir%/database.sqlite
ENV PACKAGES_PDO_DBNAME=packages
ENV PACKAGES_REDIS_HOST='redis://redis'
ENV PACKAGES_REDIS_PORT=6379

WORKDIR /app

COPY --from=0 /usr/bin/composer /usr/bin/composer

RUN apt-get update \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The webdevops image contains a helpful wrapper apt-install gettext-base procps which updates, installs and cleans afterwards.

&& apt-get install -y gettext-base procps \
&& rm -r /var/lib/apt/lists/*

COPY . /app
COPY ./docker/nginx/vhost.common.d/vhost.common.conf /opt/docker/etc/nginx/vhost.common.d/10-location-root.conf
RUN chown -R 1000:1000 /app
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce number of image layers also here by executing concatenated RUN commands

RUN composer install

RUN mkdir /root/.ssh \
&& ssh-keyscan -t rsa github.com >> /root/.ssh/known_hosts \
&& ssh-keyscan -t rsa bitbucket.org >> /root/.ssh/known_hosts \
&& ssh-keyscan -t rsa gitlab.com >> /root/.ssh/known_hosts

ENTRYPOINT envsubst < config.yml.tmpl > config.yml \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a supervisord service for the resque worker and there's also a mechanism for doing startup commands in the docker container: service.d scripts.

&& bin/console resque:worker:start \
&& /entrypoint supervisord
CMD []
65 changes: 63 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,66 @@ Some tips:
Docker support
--------------

Packages comes with an example `docker-compose.yml` that starts an nginx container and a Redis container, ready to get up and running quickly.
You can find a fully configured instance of Packages on [Docker Hub](https://hub.docker.com/r/mkerix/packages/).

### Installation

After booting up the container you still need to create the database schema by running in the container `bin/console orm:schema-tool:create`.
This container does not apply migrations automatically, you'll have to run the migrations manually in the same fashion when updating the version.

The docker-compose file in this repository is great for local development use, but in production you should consider the following setup:

```yml
version: '2'
services:
packages:
image: mkerix/packages
environment:
PACKAGES_NAME: Name
PACKAGES_HOMEPAGE: Homepage
PACKAGES_CONTACT: [email protected]
PACKAGES_BASEPATH: https://satis.example.com
PACKAGES_USER: user
PACKAGES_PASSWORD: password
PACKAGES_PDO_PATH: '%app.root_dir%/database/database.sqlite'
volumes:
- /host/packages/database:/app/database
- /host/packages/satis:/app/satis
- /host/packages/ssh:/home/application/.ssh
redis:
image: redis
```

Adjust the environment variables as well as the volume links on the host to your liking and then generate a new SSH key and known_hosts file in the ssh folder.
The generated public key needs to be added to a user with access to your composer repositories.
This is needed so that Satis can pull the repositories successfully.

### Configuration

The following environment variables can optionally be used to configure your instance.

#### Customization
- `PACKAGES_NAME` - instance name
- `PACKAGES_HOMEPAGE` - instance homepage link
- `PACKAGES_CONTACT` - contact mail
- `PACKAGES_BASEPATH` - full base URL to the instance

Visit [the documentation](http://docs.terramarlabs.com/packages/3.2/getting-started/docker) to get started.
#### Security
- `PACKAGES_SECURE` - whether Satis should be secured too or not
- `PACKAGES_USER` - username
- `PACKAGES_PASSWORD` - password

#### Database
- `PACKAGES_PDO_DRIVER` - pdo driver
- `PACKAGES_PDO_PATH` - path to the database file, e.g. for sqlite
- `PACKAGES_PDO_HOST` - database host
- `PACKAGES_PDO_USER` - database user
- `PACKAGES_PDO_PASSWORD` - database password
- `PACKAGES_PDO_DBNAME` - database name
- `PACKAGES_REDIS_HOST` - Redis host
- `PACKAGES_REDIS_PORT` - Redis port

Visit [the documentation](http://docs.terramarlabs.com/packages/3.2/getting-started/docker) to learn more.

Troubleshooting
---------------
Expand All @@ -131,4 +188,8 @@ Troubleshooting
```bash
tail -f logs/resque.log
```
4. If running in Docker make sure that all files belong to the application user. Change the ownership from within the container:
```bash
chown -R application:application /app
```

56 changes: 56 additions & 0 deletions config.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
security:
# Username and password to access the web management interface
username: '$PACKAGES_USER'
password: '$PACKAGES_PASSWORD'

doctrine:
mapping:
default:
paths: [ '%app.root_dir%/src/Entity', '%app.root_dir%/src/Plugin' ]
namespace: Terramar

database:
# Any Doctrine driver
driver: $PACKAGES_PDO_DRIVER

# Options
path: '$PACKAGES_PDO_PATH'
host: '$PACKAGES_PDO_HOST'
user: '$PACKAGES_PDO_USER'
password: '$PACKAGES_PDO_PASSWORD'
dbname: '$PACKAGES_PDO_DBNAME'

packages:
# Defines the name used in the page titles and landing page.
name: '$PACKAGES_NAME'

# If set, the homepage will be linked to from the landing page.
homepage: '$PACKAGES_HOMEPAGE'

# If set, the contact email is displayed on the landing page.
contact_email: '$PACKAGES_CONTACT'

# Needs to be set to generate a dist archive
base_path: '$PACKAGES_BASEPATH'

# If set, will place a copy of every tagged package version in the web/dist folder
archive: true

# If set, username and password will be required when attempting to access
# Satis-generated files.
secure_satis: $PACKAGES_SECURE

resque:
# Redis server host.
host: '$PACKAGES_REDIS_HOST'
# Format as either unix:///path/to/socket (note the 3 slashes) or redis://host
#host: 'unix:///var/run/redis.sock'
# If Redis is configured to require a password, you can pass it in the host:
#host: 'redis://ignored:password@host'
# Note that the username portion of the hostname is ignored and can be any value.

# Redis TCP port. If using a unix socket, this is ignored.
port: $PACKAGES_REDIS_PORT

# Redis database index where jobs will be stored.
database: 4
14 changes: 3 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
version: '2'
services:
web:
image: webdevops/php-nginx:7.1
build: .
volumes:
- .:/app
- ./docker/nginx/vhost.common.d/vhost.common.conf:/opt/docker/etc/nginx/vhost.common.d/10-location-root.conf
links:
- redis
environment:
- WEB_DOCUMENT_ROOT=/app/web
ports:
- "127.0.0.1:80:80" # Access Packages in your browser at http://127.0.0.1:80
- "127.0.0.1:443:443" # Access Packages in your browser at https://127.0.0.1:443
- 8080:80
redis:
image: redis:3.2
expose:
- "6379"
image: redis
2 changes: 1 addition & 1 deletion docker/nginx/vhost.common.d/vhost.common.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
location / {
try_files $uri $uri/ /index_dev.php$is_args$args;
try_files $uri $uri/ /index.php$is_args$args;
}