Browse Source

convert to docker-compose setup and add instructions on how to deploy the whole code locally

this includes a submodule by Florian V. which makes it easy to set up a local fake smtp server
pull/30/head
Max Mehl 7 months ago
parent
commit
e7f4d99f20
Signed by: max.mehl <max.mehl@fsfe.org> GPG Key ID: 2704E4AB371E2E92
7 changed files with 101 additions and 92 deletions
  1. 6
    11
      .drone.yml
  2. 6
    0
      .gitmodules
  3. 30
    2
      README.md
  4. 58
    4
      docker-compose.yml
  5. 1
    0
      fake-smtp-server
  6. 0
    1
      hosts
  7. 0
    74
      playbook.yml

+ 6
- 11
.drone.yml View File

@@ -1,16 +1,11 @@
pipeline:
build:
image: williamyeh/ansible:debian8
commands:
- ansible-playbook -vvv playbook.yml -i hosts --syntax-check

deploy:
image: williamyeh/ansible:debian8
secrets: [ ssh_key, redis_password ]
commands:
- mkdir /root/.ssh && echo "$SSH_KEY" > /root/.ssh/id_rsa && chmod 0600 /root/.ssh/id_rsa
- ssh-keyscan -H lund.fsfeurope.org >> ~/.ssh/known_hosts
- ansible-playbook playbook.yml -i hosts --extra-vars "REDIS_PASSWORD=$REDIS_PASSWORD"
# Run docker compose
- docker-compose up --build -d
image: tmaier/docker-compose
volumes:
- /var/run/docker.sock:/var/run/docker.sock
when:
branch: master
event: [push, tag, deployment]

+ 6
- 0
.gitmodules View File

@@ -0,0 +1,6 @@
[submodule "fake-smtp-server-dockerfile"]
path = fake-smtp-server-dockerfile
url = https://git.fsfe.org/florian.vuillemot/fake-smtp-server-dockerfile
[submodule "fake-smtp-server"]
path = fake-smtp-server
url = https://git.fsfe.org/florian.vuillemot/fake-smtp-server-dockerfile

+ 30
- 2
README.md View File

@@ -282,8 +282,36 @@ The following parameters are available only in the API configuration file:
* **confirmation-template**: name of a template defined in templates config that will be used as confirmation email. For confirmation emails already provided 2 variables: "confirmation_url" and "content". Content is the rendered email that will be sent after confirmation
* **confirmation-subject**: custom subject for confirmation email. Could contain variables

## Contribute

In order to contribute, a local testing setup is very useful. All you need is Docker and docker-compose. In the repository, just run `docker-compose up -d --build` to spin up the three containers this application includes.

### Fake SMTP server

To test emails, consider using `fake-smtp-server` linked as submodule in this repository. It allows you to use a local SMTP server which does not send the emails but lists them in your browser. Doing this, you can view and debug sent emails without having to set up this service.

To activate this service, uncomment the service `forms-fakesmtp` in `docker-compose.yml`. Afterwards, set `SMTP_HOST=forms-fakesmtp` and `SMTP_PORT=1025` in the service `forms-worker`. Do not forget to revert these changes when pushing something to the actual repo.

More info on the fake smtp server on [its official website](https://www.npmjs.com/package/fake-smtp-server).

### Use the service locally

After running docker-compose, you can access all services locally. To find out their IP addresses, run:

```
# For the forms web interface, for example 172.20.0.4
docker inspect -f '{{.NetworkSettings.Networks.forms_default.IPAddress}}' forms-web
# For the fake SMTP server, for example 172.20.0.5
docker inspect -f '{{.NetworkSettings.Networks.forms_default.IPAddress}}' forms-fakesmtp
```

Now you either replace the URLs of a form with `http://$ipadress:8080/email` (for example in your browser with developer tools), or send POST requests via curl like: `curl -X POST "http://172.20.0.4:8080/email" -d "appid=pmpc-sign&name=tester1&confirm=mail@example.com&permissionPriv=yes"`.

On `http://172.20.0.5:1080` you can then see the sent email.

## License
This software is copyright 2018 by the Free Software Foundation Europe e.V.

This software is copyright 2019 by the Free Software Foundation Europe e.V.
and licensed under the GPLv3 license. For details see the "LICENSE" file in
the top level directory of https://git.fsfe.org/fsfe/forms/
the top level directory of https://git.fsfe.org/fsfe-system-hackers/forms/


+ 58
- 4
docker-compose.yml View File

@@ -1,6 +1,60 @@
version: "2"
version: '3'
services:
redis:
forms-redis:
container_name: forms-redis
image: redis:3.2
ports:
- "6379:6379"
restart: always
expose:
- 6379

forms-web:
container_name: forms-web
build:
context: .
dockerfile: Dockerfile-web
image: forms-web
restart: always
expose:
- 8080
environment:
- VIRTUAL_HOST=forms.fsfe.org
- LETSENCRYPT_HOST=forms.fsfe.org
- LETSENCRYPT_EMAIL=contact@fsfe.org
- REDIS_HOST=forms-redis
- REDIS_PORT=6379
volumes:
- "/srv/forms:/store:rw"

forms-worker:
container_name: forms-worker
build:
context: .
dockerfile: Dockerfile-worker
image: forms-worker
environment:
- REDIS_HOST=forms-redis
- REDIS_PORT=6379
- SMTP_HOST=mail.fsfe.org
- SMTP_PORT=25
volumes:
- "/srv/forms:/store:rw"

# forms-fakesmtp:
# container_name: forms-fakesmtp
# build:
# context: ./fake-smtp-server
# dockerfile: Dockerfile-smtp
# image: forms-fakesmtp
# ports:
# - 1025
# - 1080

# Connect the container which exposes the service to the 'bridge' network as
# this is where the reverse proxy is
connect-bridge:
image: docker:dind
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- forms-web
command: /bin/sh -c 'docker network connect bridge forms-web'

+ 1
- 0
fake-smtp-server

@@ -0,0 +1 @@
Subproject commit bb86c322dc0e6bee61472046eb5f83a060658bd7

+ 0
- 1
hosts View File

@@ -1 +0,0 @@
lund.fsfeurope.org

+ 0
- 74
playbook.yml View File

@@ -1,74 +0,0 @@
---
- hosts: lund.fsfeurope.org
remote_user: root

tasks:
- name: create network
docker_network:
name: forms-net
ipam_options:
subnet: '192.168.201.40/29'
state: present

- name: run redis
docker_container:
name: forms-redis
image: redis:3.2
state: started
restart: yes
restart_policy: always
exposed_ports:
- 6379
networks:
- name: forms-net
ipv4_address: '192.168.201.44'
alias: forms-redis

- name: build web container
command: docker build -f Dockerfile-web -t forms-web https://git.fsfe.org/fsfe-system-hackers/forms.git

- name: build worker container
command: docker build -f Dockerfile-worker -t forms-worker https://git.fsfe.org/fsfe-system-hackers/forms.git

- name: run web app
docker_container:
name: forms-web
image: forms-web
state: started
restart: yes
restart_policy: always
exposed_ports:
- 8080
env:
REDIS_HOST: "formsredis"
REDIS_PORT: 6379
VIRTUAL_HOST: forms.fsfe.org
LETSENCRYPT_HOST: forms.fsfe.org
LETSENCRYPT_EMAIL: contact@fsfe.org
networks:
- name: forms-net
ipv4_address: '192.168.201.42'
links:
- forms-redis:formsredis
volumes:
- "/srv/forms:/store:rw"

- name: run worker app
docker_container:
name: forms-worker
image: forms-worker
state: started
restart: yes
restart_policy: always
env:
REDIS_HOST: "formsredis"
REDIS_PORT: 6379
SMTP_HOST: "mail.fsfe.org"
SMTP_PORT: 25
networks:
- name: forms-net
ipv4_address: '192.168.201.43'
links:
- forms-redis:formsredis
volumes:
- "/srv/forms:/store:rw"

Loading…
Cancel
Save