Skip to content

Commit 76d0865

Browse files
authored
Merge pull request #134 from wayofdev/ci/e2e-testing
2 parents 65b85e0 + d86b21a commit 76d0865

File tree

2 files changed

+95
-68
lines changed

2 files changed

+95
-68
lines changed

.env.example

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1+
#
12
# SS = Shared Services
23
# https://docs.docker.com/compose/reference/envvars/#compose_project_name
4+
#
35
COMPOSE_PROJECT_NAME=ss
46

7+
#
58
# Domain, under which default, shared services will run.
69
# Default: .wod
710
# Example subdomains, under which services will run under:
811
# - pg-admin.wod.docker
912
# - router.wod.docker
1013
# - ui.wod.docker
11-
# Can be left blank, but then $TLS_DOMAINS need to contain all top level domains
14+
# Can be left blank, but then $TLS_DOMAINS need to contain all top level domains of your projects.
15+
#
1216
# Example:
17+
# Using empty SHARED_DOMAIN_SEGMENT=""
1318
# TLS_DOMAINS="pg-admin.docker router.docker ui.docker"
19+
# Using custom SHARED_DOMAIN_SEGMENT=".wod"
20+
# TLS_DOMAINS="pg-admin.wod.docker router.wod.docker ui.wod.docker"
21+
#
1422
SHARED_DOMAIN_SEGMENT=
1523

24+
#
1625
# Specify domains for mkcert
1726
# Because of browser limitations, each top-level domain should be added separately.
1827
# This ensures that certificates are correctly recognized by browsers.
@@ -47,6 +56,9 @@ TLS_DOMAINS="ui.docker router.docker pg-admin.docker *.wod.docker *.tpl.wod.dock
4756
# For more information, see:
4857
# https://github.com/DrPsychick/docker-dnsmasq
4958
#
59+
# Note: To use, for example .mac domain, you need to change
60+
# DMQ_GLOBAL=address=/docker/127.0.0.1 (to =>) DMQ_GLOBAL=address=/mac/127.0.0.1
61+
#
5062
DMQ_DHCP_DNS=dhcp-option=6,172.17.10.1,8.8.8.8,8.8.4.4
5163
DMQ_DHCP_GATEWAY=dhcp-option=3,172.17.10.1
5264
DMQ_DHCP_PXE=

README.md

+82-67
Original file line numberDiff line numberDiff line change
@@ -77,119 +77,134 @@ If you **like/use** this project, please consider ⭐️ **starring** it. Thanks
7777

7878
<br>
7979

80-
## ⚙️ Configuration
80+
## 🚀 Quick Start (macOS)
8181

82-
### → Cloning and setting up envs
83-
84-
1. Clone repository:
82+
1. Install Homebrew (**optional** if not installed):
8583

8684
```bash
87-
git clone git@github.com:wayofdev/docker-shared-services.git
85+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
8886
```
8987

90-
2. Generate default .env file:
88+
2. **Install `mkcert` and `nss`:**
89+
90+
`mkcert` is a tool that creates locally-trusted development certificates, `nss` provides support of mkcert certificates in macOS.
9191

9292
```bash
93-
make env
93+
brew install mkcert nss
9494
```
9595

96-
Edit the created `.env` file if necessary. You may want to change the default domain.
97-
98-
<br>
99-
100-
## 💻 Usage
101-
102-
### → Running with a blank shared domain segment
96+
3. **Create shared projects Directory:**
10397

104-
Leave the `SHARED_DOMAIN_SEGMENT` blank to run shared services under the first level domain. For example:
98+
This repository should be run once per machine, so let's create a shared directory for this project:
10599

106-
| Address |
107-
|-----------------|
108-
| router.docker |
109-
| pg-admin.docker |
110-
| ui.docker |
111-
| etc. |
112-
113-
<br>
114-
115-
### → Running with a default or custom shared domain segment
116-
117-
Set the segment to run shared services under a subdomain: `SHARED_DOMAIN_SEGMENT=.wod`. Services will run under that segment. For example:
100+
```bash
101+
mkdir -p ~/projects/infra && cd ~/projects/infra
102+
```
118103

119-
| Address |
120-
|-------------------------|
121-
| router.**wod**.docker |
122-
| pg-admin.**wod**.docker |
123-
| ui.**wod**.docker |
124-
| etc. |
104+
4. **Clone this repository:**
125105

126-
<br>
106+
```bash
107+
git clone \
108+
[email protected]:wayofdev/docker-shared-services.git \
109+
~/projects/infra/docker-shared-services && \
110+
cd ~/projects/infra/docker-shared-services
111+
```
127112

128-
### → SSL certificates
113+
5. **Create `.env` file:**
129114

130-
Don't forget to include first level domains into the `TLS_DOMAINS` variable. Default certificates will be created for these domains and wildcards:
115+
Generate a default `.env` file, which contains configuration settings for the project.
131116

132-
| SSL certificate | Comments |
133-
|------------------|-------------------------------------------------------------------------------------------------------------|
134-
| ui.docker | Included as fallback, if `SHARED_DOMAIN_SEGMENT` was left blank. |
135-
| router.docker | Included as fallback, if `SHARED_DOMAIN_SEGMENT` was left blank. |
136-
| pg-admin.docker | Included as fallback, if `SHARED_DOMAIN_SEGMENT` was left blank. |
137-
| *.wod.docker | All subdomains under this wildcard. **Only one level of nesting **will work in most of the browsers****. |
138-
| *.tpl.wod.docker | For default template, generated from [laravel-starter-tpl](https://github.com/wayofdev/laravel-starter-tpl) |
117+
```bash
118+
make env
119+
```
139120

140-
<br>
121+
Open this file and read the notes inside to make any necessary changes to fit your setup.
141122

142-
### → Finishing
123+
6. **Install root certificate** and generate default project certs:
143124

144-
1. Install root certificate into system and generate default certs:
125+
This step installs the root certificate into your system's trust store and generates default SSL certificates for your local domains, which are listed in the `.env` file, under variable `TLS_DOMAINS`.
145126

146127
```bash
147128
make cert-install
148129
```
149130

150-
2. (Optional) Enable docker-compose.override file to run extra services, like pg-admin and others:
131+
Currently, on macOS you may need to enter password several times to allow mkcert to install root certificate.
132+
This is a one-time operation and details can be found in this upstream [issue](https://github.com/FiloSottile/mkcert/issues/415).
151133

152-
```bash
153-
make override
154-
```
134+
7. **Run this project:**
155135

156-
3. Run this repository:
136+
Start the Docker services defined in the repository.
157137

158138
```bash
159139
make up
160140
```
161141

162-
4. Check that everything works:
142+
8. **Check that all Docker services are running:**
163143

164144
```bash
165145
make ps
166146
make logs
167147
```
168148

169-
<br>
170-
171-
### → Outcome
149+
9. **Ping `router.docker` to check if DNS is working:**
172150

173-
Services will be running under shared docker network, called `ss_shared_network` and all microservices, that will share same network, will be visible for Traefik, and local DNS, served by dnsmasq, will be available.
151+
Ensure that the DNS setup is functioning correctly.
174152

175-
**Traefik dashboard**[https://router.wod.docker](https://router.wod.docker/dashboard/#/)
153+
```bash
154+
ping router.docker
155+
```
176156

177-
![Traefik dashboard](.github/assets/traefik.png?raw=true "Traefik dashboard example")
157+
10. **Access Traefik dashboard:**
178158

179-
**Portrainer**<https://ui.wod.docker> or <https://ui.docker>
159+
Open [https://router.docker](https://router.docker)
180160

181-
**Pg-admin** (if `docker-compose.override.yaml` was enabled) — <https://pg-admin.wod.docker> or <https://pg-admin.docker>
161+
At this point, you should have a working local development environment with DNS and SSL support for your projects.
182162

183163
<br>
184164

185-
## 🧪 Testing
186-
187-
You can check `Makefile` to get full list of commands for local testing. For testing, you can use these commands to test whole role or separate tasks:
188-
189-
Testing docker-compose using `dcgoss`:
165+
## ⚡️ Connecting your Projects to Shared Services
166+
167+
To connect your projects to the shared services, configure your project's `docker-compose.yaml` file to connect to the shared network and Traefik.
168+
169+
For a quick example, you can check this [Laravel Starter Template](https://github.com/wayofdev/laravel-starter-tpl) repository's [docker-compose.yaml](https://github.com/wayofdev/laravel-starter-tpl/blob/develop/docker-compose.yaml) file, which includes a sample configuration for a Laravel project.
170+
171+
### → Sample Configuration
172+
173+
Your project should use the shared Docker network `network.ss` and Traefik labels to expose services to the outside world.
174+
175+
```diff
176+
---
177+
178+
services:
179+
web:
180+
image: wayofdev/nginx:k8s-alpine-latest
181+
container_name: ${COMPOSE_PROJECT_NAME}-web
182+
restart: on-failure
183+
+ networks:
184+
+ - default
185+
+ - shared
186+
depends_on:
187+
- app
188+
links:
189+
- app
190+
volumes:
191+
- ./app:/app:rw,cached
192+
- ./.env:/app/.env
193+
+ labels:
194+
+ - traefik.enable=true
195+
+ - traefik.http.routers.api-${COMPOSE_PROJECT_NAME}-secure.rule=Host(`api.${COMPOSE_PROJECT_NAME}.docker`)
196+
+ - traefik.http.routers.api-${COMPOSE_PROJECT_NAME}-secure.entrypoints=websecure
197+
+ - traefik.http.routers.api-${COMPOSE_PROJECT_NAME}-secure.tls=true
198+
+ - traefik.http.services.api-${COMPOSE_PROJECT_NAME}-secure.loadbalancer.server.port=8880
199+
+ - traefik.docker.network=network.ss
200+
201+
networks:
202+
+ shared:
203+
+ external: true
204+
+ name: network.ss
205+
+ default:
206+
+ name: project.laravel-starter-tpl
190207

191-
```bash
192-
make test
193208
```
194209

195210
<br>

0 commit comments

Comments
 (0)