Skip to content

Commit e9f5dc9

Browse files
committed
feat: initial commit
0 parents  commit e9f5dc9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4622
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
.idea
3+

DOCKER_TIPS.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## Typical Docker Commands
2+
### Start all environments services
3+
> docker-compose up --build
4+
5+
### Restart a specific container
6+
> docker restart [service name]
7+
8+
### List all containers
9+
> docker ps -a
10+
11+
### List running containers
12+
> docker ps
13+
14+
### See used space
15+
> docker system df
16+
17+
### Remove un-used data
18+
> docker system prune
19+
20+
## Passwords
21+
### PostgreSQL
22+
> username: postgres_user
23+
> password: postgres_pass
24+
25+
### MySql
26+
> username: mysql_user
27+
> password: mysql_pass
28+
29+
### MariaDB
30+
> username: mariadb_user
31+
> password: mariadb_pass
32+
33+
34+
## Running Xdebug with PHPStorm alongside Docker.
35+
Any logic that needs to speak to the host machine will need to point to the IP of `10.254.254.254`.
36+
37+
For Xdebug to work through PHPStorm first execute:
38+
39+
```
40+
sudo ifconfig lo0 alias 10.254.254.254
41+
```

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Sourcetoad Internal Development Tools (SIDT)
2+
3+
Sourcetoad Internal Development Tools includes a growing collection of tutorials
4+
for managing IDEs, hooking up tools with Docker and any combination of those
5+
things.
6+
7+
Additionally, this repository holds our data source services which is
8+
a collection of databases and other services that projects will more than likely
9+
need. It also provides a proxy setup via nginx-proxy so that multiple projects
10+
can be run at the same time without the need for different ports.
11+
12+
This means docker configurations for each project only needs to worry about the
13+
the language and other tools it may need, as the databases and other services are
14+
standardized in this project. Since most cloud providers provide managed versions
15+
of these services, you likely would not use a docker version of them in production.
16+
17+
## Docker
18+
19+
### devop-tools (data source services / domain tools)
20+
1. Execute `git clone [email protected]:sourcetoad/devop-tools.git`
21+
2. `cd devop-tools`
22+
3. `cd ./docker/data-source-services/`
23+
4. Execute `./network-creation.sh`
24+
- If this fails, then manual configuration is necessary before compilation. Perform the following:
25+
1. `docker network create nginx-proxy`
26+
2. `docker network create st-mariadb-101`
27+
3. `docker network create st-mysql-56`
28+
4. `docker network create st-postgres-95`
29+
5. `docker network create st-redis-32`
30+
5. Execute `docker-compose up --build`
31+
5. Wait for the terminal to complete executing.
32+
6. You now have Sourcetoad data sources running and logging to the console.
33+
34+
## Examples
35+
Inside the `examples` folder you will find example Docker configurations for
36+
popular frameworks like Laravel and Yii2.
37+
38+
The examples make the assumption that any domain used for local development is
39+
already added to the `/etc/hosts` file. You can edit to add `127.0.0.1 domain.docker`.
40+
41+
## Docs
42+
* [Setting up D4M-NFS](docs/d4m-nfs/README.md)
43+
* [Setting up Nginx-Proxy](docs/nginx-proxy/README.md)
44+
* [Setting up PHP Testing in PHPStorm](docs/phpstorm-docker/README.md)
45+
* [Setting up Python Debugging in Pycharm](docs/pycharm-debugging/README.md)
46+
* [Building a new Upsource Project](docs/upsource/README.md)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Last two digits of port number are the MAJOR.MINOR of the data source
2+
# Everything ahead of the last two digits are standard for the given service
3+
#
4+
# Network name is st-{service name}-{service MAJOR.MINOR}
5+
version: '2'
6+
services:
7+
nginxproxy:
8+
# Enable nginx debug and increase output verbosity
9+
# command: [nginx-debug, '-g', 'daemon off;']
10+
image: jwilder/nginx-proxy
11+
container_name: sourcetoad_nginx_proxy
12+
ports:
13+
- "80:80"
14+
volumes:
15+
- /var/run/docker.sock:/tmp/docker.sock:ro
16+
- ./proxy_increase.conf:/etc/nginx/proxy.conf
17+
networks:
18+
- nginx-proxy
19+
postgres95:
20+
image: postgres:9.5
21+
container_name: sourcetoad_postgres95
22+
ports:
23+
- "5495:5432"
24+
environment:
25+
- POSTGRES_USER=postgres_user
26+
- POSTGRES_PASSWORD=postgres_pass
27+
networks:
28+
- st-postgres-95
29+
command: "postgres
30+
-c logging_collector='on'
31+
-c log_directory='/var/log/postgresql'
32+
-c log_filename='%Y-%m-%d.log'
33+
-c log_line_prefix='%t %v '
34+
-c log_statement='all'"
35+
mysql56:
36+
image: mysql:5.6
37+
container_name: sourcetoad_mysql56
38+
ports:
39+
- "3356:3306"
40+
environment:
41+
- MYSQL_ROOT_PASSWORD=root
42+
- MYSQL_USER=mysql_user
43+
- MYSQL_PASSWORD=mysql_pass
44+
networks:
45+
- st-mysql-56
46+
mariadb101:
47+
image: mariadb:10.1
48+
container_name: sourcetoad_mariadb101
49+
ports:
50+
- "33101:3306"
51+
environment:
52+
- MYSQL_ROOT_PASSWORD=root
53+
- MYSQL_USER=mariadb_user
54+
- MYSQL_PASSWORD=mariadb_pass
55+
networks:
56+
- st-mariadb-101
57+
redis32:
58+
image: redis:3.2-alpine
59+
command: redis-server --appendonly yes
60+
container_name: sourcetoad_redis32
61+
ports:
62+
- "6332:6379"
63+
networks:
64+
- st-redis-32
65+
networks:
66+
nginx-proxy:
67+
external:
68+
name: nginx-proxy
69+
st-postgres-95:
70+
external:
71+
name: st-postgres-95
72+
st-mysql-56:
73+
external:
74+
name: st-mysql-56
75+
st-mariadb-101:
76+
external:
77+
name: st-mariadb-101
78+
st-redis-32:
79+
external:
80+
name: st-redis-32
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
echo "Creating container networks:\n"
2+
docker network create nginx-proxy
3+
docker network create st-mariadb-101
4+
docker network create st-mysql-56
5+
docker network create st-postgres-95
6+
docker network create st-redis-32
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# nginx-proxy uses defaults for client_max_body_size, which is low for some projects
2+
client_max_body_size 1000m;
3+
4+
# nginx-proxy uses defaults for proxy timeouts, which is low if using remote debugging
5+
proxy_connect_timeout 5;
6+
proxy_send_timeout 3600;
7+
proxy_read_timeout 3600;
8+
9+
# nginx-proxy sets the values below by default only IF a proxy change is not defined, therefore, we duplicate the default values
10+
proxy_http_version 1.1;
11+
proxy_buffering off;
12+
proxy_set_header Host $http_host;
13+
proxy_set_header Upgrade $http_upgrade;
14+
proxy_set_header Connection $proxy_connection;
15+
proxy_set_header X-Real-IP $remote_addr;
16+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
17+
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
18+
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
19+
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
20+
21+
# Mitigate httpoxy attack (see README for details)
22+
proxy_set_header Proxy "";

docs/d4m-nfs/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# D4M-NFS on Mac OSX
2+
3+
*Warning: Currently D4M-NFS is broken after the update to 17.12.0-ce-mac64. The issue can be followed here: https://github.com/IFSight/d4m-nfs/issues/55*
4+
5+
In order to speed up Docker instances on Mac OSX, D4M-NFS is a great solution that will increase file read/write performance up to 6X times.
6+
7+
### Steps for success!
8+
9+
1. Shut down any docker containers `docker stop $(docker ps -a -q)` otherwise you could get a "loop of death" which isn't fun from what I've read.
10+
2. Quit the docker daemon/application.
11+
3. Kill d4m if you have an old, non-working version running. You can determine this by running `screen -r d4m`
12+
4. `cd ~/`
13+
5. `git clone [email protected]:IFSight/d4m-nfs.git ~/d4m-nfs`
14+
6. `cd ~/d4m-nfs/etc`
15+
7. `touch d4m-nfs-mounts.txt`
16+
8. Add the text `/Users/yourusername:/Users/yourusername:0:0`
17+
- Do not add /Volumes here, this should be the only thing added for this file.
18+
9. Go into docker and remove everything else except /tmp.
19+
![docker](images/docker-file-sharing.png)
20+
- If you add other directories, this will not work as it will create conflicts with the NFS systems.
21+
10. `cd ~/d4m-nfs`
22+
11. `/bin/bash d4m-nfs.sh`
23+
12. `sudo vim /etc/exports`
24+
- Remove any other non-commented lines except for `"/Users/yourusername" -alldirs -mapall=0:0 localhost`
25+
- If you see anything other than this you were not running with bash.
26+
11. Start up ya dockers, rejoice!
27+
28+
#### Mount Points
29+
30+
I have not had success with adding code to a /mnt point and getting D4M-NFS to work. Please update the documentation if you have a solution.
47.7 KB
Loading

docs/nginx-proxy/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# nginx-proxy
2+
3+
The data source services includes an application called nginx-proxy. This allows you to run multiple projects at the same time on different virtual hosts without port conflicts. You do not need to expose the webserver to the host machine through a port map.
4+
5+
In order for nginx-proxy to operate, you must follow the following steps.
6+
7+
## Setup hosts file
8+
1. Choose a virtual host for your project. RFC-6761 recommends against using a .dev TLD, and instead using a .localhost TLD. Therefore, your domain might be mysite.localhost
9+
2. Edit your hosts file and add this domain to your loopback address (127.0.0.1) using your preferred text editor. *make sure to use sudo*
10+
```
11+
sudo nano /etc/hosts
12+
13+
add:
14+
127.0.0.1 mysite.localhost
15+
```
16+
17+
## Setup docker-compose for project
18+
1. In order for nginx-proxy to detect and proxy to the correct virtual host, you must first identify the container that is running the "web server." In a php project, this would be the nginx container, for example.
19+
2. You will then add an environment variable of `VIRTUAL_HOST=mysite.localhost` to this service, place that service on the nginx-proxy network, and import that nginx-proxy network to the project. See the below snippet:
20+
21+
```
22+
version: '2'
23+
services:
24+
[APP_NAME]_nginx:
25+
image: nginx:latest
26+
environment:
27+
- VIRTUAL_HOST=mysite.localhost
28+
```

docs/phpstorm-docker/README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# PHPStorm & Docker
2+
3+
The goal for this tutorial is to help containerize an application
4+
to leverage the tools within PHPStorm (Test Suite, Coverage, etc).
5+
6+
To do this the following things need to happen:
7+
8+
1) Setup Docker for Mac in PHPStorm.
9+
2) Setup Language (PHP in this example) to use a remote interpreter.
10+
3) Fix the paths to match our standard (/code for project code)
11+
4) Setup Tests (PHPUnit or Codeception) to use a special docker-compose file.
12+
13+
We are assuming the following things:
14+
15+
1) Docker compose file exists for the project.
16+
2) The project is already running via (docker-compose up --build)
17+
3) Some small knowledge of Docker
18+
19+
### Setup Docker for Mac in PHPStorm
20+
21+
Head to Preferences and go to `Build, Execution, Deployment -> Docker`. Create a
22+
an item called "Docker" using the daemon option "Docker for Mac".
23+
24+
![](./assets/docker-phpstorm.png)
25+
26+
### Creating an isolated docker-compose for testing.
27+
28+
In order for PHPStorm to run tests without affecting containers. You need to
29+
create a new container that matches whatever container your code works on.
30+
31+
For example, here a random PHP project `docker-compose-phpstorm.yml` file.
32+
33+
```
34+
version: '2'
35+
services:
36+
project-test:
37+
container_name: sourcetoad_project_test
38+
build: .
39+
volumes:
40+
- ../:/code:delegated
41+
networks:
42+
- project-internal
43+
- st-mariadb-101
44+
- st-redis-32
45+
networks:
46+
project-internal:
47+
st-redis-32:
48+
external:
49+
name: st-redis-32
50+
st-mariadb-101:
51+
external:
52+
name: st-mariadb-101
53+
```
54+
55+
As you can see, it is a subset of the compose file. It only includes a clone of
56+
the PHP container, keeping intact the networks, mounts and env file. This allows
57+
the new container to have access to databases and files which may be needed in
58+
the test suite. You can use multiple compose files if you need one for an
59+
acceptance test container.
60+
61+
If your project requires multiple containers in the testing aspect. Recommend
62+
creating descriptive container names, like `project-codeception` so you could
63+
additionally have `project-behat` if needed.
64+
65+
### Setup Docker Container for PHP Language
66+
67+
Head to Preferences and go to `Languages & Frameworks > PHP`. From here we are
68+
going to click the "..." next to the CLI Interpreter option in order to create a
69+
new "Docker Compose" interpreter. Using the file we created above, we will
70+
select that one. Once selected, you need to select the container to use. This
71+
will more than likely be auto-selected for you.
72+
73+
![](./assets/docker-findphp.png)
74+
75+
### Setup Docker Container for PHP Test Framework
76+
77+
Head to Preferences and go to `Languages & Framework > PHP > Test Frameworks`.
78+
Once here, click the "+" icon in top right to create a new test environment. You
79+
will more than likely select one of the following:
80+
81+
* PHPUnit by Remote Interpreter
82+
* Codeception by Remote Interpreter
83+
* Behat by Remote Interpreter
84+
* PHPSpec by Remote Interpreter
85+
86+
Once you select one, you will need to select the container to run this tool at.
87+
You already created the container and loaded it in the previous steps. So just
88+
select the container that works. Once loaded, you need to put in the file path
89+
to that binary. In the screenshot below, we are using Codeception so looking
90+
for `/code/vendor/bin/codecept`. The `/code` is what we use to mount our code
91+
into the container. This pattern may be different depending on lots of factors.
92+
93+
Finally, for this step you need to make sure you specify the configuration file
94+
for the test framework. The default location may be wrong, in the photo below I
95+
gave the direct path to the configuration like: `/code/codeception.yml`.
96+
97+
![](./assets/docker-codecept.png)
98+
99+
### Setup Test Case to run in IDE
100+
101+
Head "Run -> Edit Configurations". Now you need to select the test framework
102+
that matches the test framework you attached into the container. Since, we used
103+
Codeception, we will continue to use Codeception for this demo.
104+
105+
Our goal is to select the "Defined in the Configuration File". No matter the
106+
tool, if you configured it correctly, we can just use those values and inherit.
107+
108+
This demo has made an additional change and requested Codeception to only run
109+
the "unit" test suite.
110+
111+
![](./assets/docker-unittest.png)
112+
113+
### Run the Test Suite
114+
115+
Now we should be able to the launch the test suite. Our docker-compose file will
116+
execute, spawning a new "test" container based off our main language container.
117+
118+
This will then proceed to execute the test framework we specified, collecting
119+
the results and parsing them into the UI.
120+
121+
This can be shown below:
122+
123+
![](./assets/docker-testpass.png)
124+
125+
With that you have successfully hooked the test suites, while keeping Docker
126+
inside PHPStorm.
127+
128+

0 commit comments

Comments
 (0)