Skip to content

Commit 7efe6dd

Browse files
committed
Initial commit
0 parents  commit 7efe6dd

File tree

27 files changed

+1285
-0
lines changed

27 files changed

+1285
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [damalis]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

README.md

Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
# [full stack nginx Rails for everyone with docker compose](https://github.com/damalis/full-stack-nginx-rails-for-everyone-with-docker-compose)
2+
3+
If You want to build a website with Rails at short time;
4+
5+
#### Full stack Nginx Rails:
6+
<p align="left"> <a href="https://rubyonrails.org/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/4223?s=200&v=4" alt="Rails" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://www.docker.com/" target="_blank" rel="noreferrer"> <img src="https://raw.githubusercontent.com/github/explore/80688e429a7d4ef2fca1e82350fe8e3517d3494d/topics/docker/docker.png" alt="docker" width="40" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://mariadb.org/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/5877084?s=200&v=4" alt="mariadb" height="50" width="50"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://www.nginx.com" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/1412239?s=200&v=4" alt="nginx" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://redis.io" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/1529926?s=200&v=4" alt="redis" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="#" target="_blank" rel="noreferrer"> <img src="https://raw.githubusercontent.com/github/explore/80688e429a7d4ef2fca1e82350fe8e3517d3494d/topics/bash/bash.png" alt="Bash" height="50" width="50" /> </a>&nbsp;&nbsp;&nbsp;
7+
<a href="https://www.phpmyadmin.net/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/1351977?s=200&v=4" alt="phpmyadmin" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://letsencrypt.org/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/17889013?s=200&v=4" alt="letsencrypt" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://www.portainer.io/?hsLang=en" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/22225832?s=200&v=4" alt="portainer" height="40" width="40"/> </a> </p>
8+
9+
Plus, manage docker containers with Portainer.
10+
11+
#### With this project you can quickly run the following:
12+
13+
- [Rails](https://github.com/rails)
14+
- [webserver (nginx)](https://hub.docker.com/_/nginx)
15+
- [certbot (letsencrypt)](https://hub.docker.com/r/certbot/certbot)
16+
- [phpMyAdmin](https://hub.docker.com/r/phpmyadmin/phpmyadmin/)
17+
- [database](https://hub.docker.com/_/mariadb)
18+
- [redis](https://hub.docker.com/_/redis)
19+
- [backup](https://hub.docker.com/r/futurice/docker-volume-backup)
20+
21+
#### For certbot (letsencrypt) certificate:
22+
23+
- [Set DNS configuration of your domain name](https://support.google.com/a/answer/48090?hl=en)
24+
25+
#### IPv4/IPv6 Firewall
26+
Create rules to open ports to the internet, or to a specific IPv4 address or range.
27+
28+
- http: 80
29+
- https: 443
30+
- portainer: 9001
31+
- phpmyadmin: 9090
32+
33+
#### Contents:
34+
35+
- [Auto Configuration and Installation](#automatic)
36+
- [Requirements](#requirements)
37+
- [Manual Configuration and Installation](#manual)
38+
- [Portainer Installation](#portainer)
39+
- [Usage](#usage)
40+
- [Website](#website)
41+
- [Webserver](#webserver)
42+
- [Database](#database)
43+
- [Redis](#redis)
44+
- [phpMyAdmin](#phpmyadmin)
45+
- [backup](#backup)
46+
47+
## Automatic
48+
49+
### Exec install shell script for auto installation and configuration
50+
51+
download with
52+
53+
```
54+
git clone https://github.com/damalis/full-stack-nginx-rails-for-everyone-with-docker-compose.git
55+
```
56+
57+
Open a terminal and `cd` to the folder in which `docker-compose.yml` is saved and run:
58+
59+
```
60+
cd full-stack-nginx-rails-for-everyone-with-docker-compose
61+
chmod +x install.sh
62+
./install.sh
63+
```
64+
65+
## Requirements
66+
67+
Make sure you have the latest versions of **Docker** and **Docker Compose** installed on your machine.
68+
69+
- [How install docker](https://docs.docker.com/engine/install/)
70+
- [How install docker compose](https://docs.docker.com/compose/install/)
71+
72+
Clone this repository or copy the files from this repository into a new folder. In the **docker-compose.yml** file you may change the database from MariaDB to MySQL.
73+
74+
Make sure to [add your user to the `docker` group](https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user).
75+
76+
## Manual
77+
78+
### Configuration
79+
80+
download with
81+
```
82+
git clone https://github.com/damalis/full-stack-nginx-rails-for-everyone-with-docker-compose.git
83+
```
84+
85+
Open a terminal and `cd` to the folder in which `docker-compose.yml` is saved and run:
86+
87+
```
88+
cd full-stack-nginx-rails-for-everyone-with-docker-compose
89+
```
90+
91+
Copy the example environment into `.env`
92+
93+
```
94+
cp env.example .env
95+
```
96+
97+
Edit the `.env` file to change values of ```LOCAL_TIMEZONE```, ```DOMAIN_NAME```, ```DIRECTORY_PATH```, ```LETSENCRYPT_EMAIL```, ```DB_USER```, ```DB_PASSWORD```, ```DB_NAME```, ```MYSQL_ROOT_PASSWORD```, ```PMA_CONTROLUSER```, ```PMA_CONTROLPASS```, ```PMA_HTPASSWD_USERNAME``` and ```PMA_HTPASSWD_PASSWORD```.
98+
99+
LOCAL_TIMEZONE=[to see local timezones](https://docs.diladele.com/docker/timezones.html)
100+
101+
DIRECTORY_PATH=```pwd``` at command line
102+
103+
and
104+
105+
```
106+
cp ./phpmyadmin/apache2/sites-available/default-ssl.sample.conf ./phpmyadmin/apache2/sites-available/default-ssl.conf
107+
```
108+
109+
change example.com to your domain name in ```./phpmyadmin/apache2/sites-available/default-ssl.conf``` file.
110+
111+
### Installation
112+
113+
Firstly: will create external volume
114+
115+
```
116+
docker volume create --driver local --opt type=none --opt device=${DIRECTORY_PATH}/certbot --opt o=bind certbot-etc
117+
```
118+
119+
```
120+
docker compose up -d
121+
```
122+
123+
then reloading for webserver ssl configuration
124+
125+
```
126+
docker container restart webserver
127+
```
128+
129+
The containers are now built and running. You should be able to access the Rails installation with the configured IP in the browser address. `https://example.com`.
130+
131+
For convenience you may add a new entry into your hosts file.
132+
133+
## Portainer
134+
135+
```
136+
docker volume create portainer_data
137+
docker compose -f portainer-docker-compose.yml -p portainer up -d
138+
```
139+
manage docker with [Portainer](https://www.portainer.io/) is the definitive container management tool for Docker, Docker Swarm with it's highly intuitive GUI and API.
140+
141+
You can also visit `https://example.com:9001` to access portainer after starting the containers.
142+
143+
## Usage
144+
145+
#### You could manage docker containers without command line with portainer.
146+
147+
### Show both running and stopped containers
148+
149+
The docker ps command only shows running containers by default. To see all containers, use the -a (or --all) flag:
150+
151+
```
152+
docker ps -a
153+
```
154+
155+
### Starting containers
156+
157+
You can start the containers with the `up` command in daemon mode (by adding `-d` as an argument) or by using the `start` command:
158+
159+
```
160+
docker compose start
161+
```
162+
163+
### Stopping containers
164+
165+
```
166+
docker compose stop
167+
```
168+
169+
### Removing containers
170+
171+
To stop and remove all the containers use the `down` command:
172+
173+
```
174+
docker compose down
175+
```
176+
177+
to remove portainer and the other containers
178+
```
179+
docker rm -f $(docker ps -a -q)
180+
```
181+
182+
Use `-v` if you need to remove the database volume which is used to persist the database:
183+
184+
```
185+
docker compose down -v
186+
```
187+
188+
to remove external certbot-etc and portainer and the other volumes
189+
190+
```
191+
docker volume rm $(docker volume ls -q)
192+
```
193+
194+
to remove portainer and the other images
195+
```
196+
docker rmi $(docker image ls -q)
197+
```
198+
199+
### Project from existing source
200+
201+
Copy all files into a new directory:
202+
203+
You can now use the `up` command:
204+
205+
```
206+
docker compose up -d
207+
```
208+
209+
### Docker run reference
210+
211+
[https://docs.docker.com/engine/reference/run/](https://docs.docker.com/engine/reference/run/)
212+
213+
### Website
214+
215+
You should see the "Rails version: ... and Ruby version: ..." page in your browser. If not, please check if your installation satisfies Rails's requirements.
216+
217+
Blocked host: must add the contents of config/environments/development.rb with the following:
218+
219+
```config.hosts << "example.com"``` then ```docker container restart rails```
220+
221+
```
222+
https://example.com
223+
```
224+
225+
add and/or remove rails site folders and files with any ftp client program in ```./rails``` folder.
226+
<br />You can also visit `https://example.com` to access website after starting the containers.
227+
228+
#### Webserver
229+
230+
add or remove code in the ```./webserver/templates/nginx.conf.template``` file for custom nginx configurations
231+
232+
[https://www.nginx.com/resources/wiki/start/topics/examples/simplerubyfcgi/](https://www.nginx.com/resources/wiki/start/topics/examples/simplerubyfcgi/)
233+
234+
#### Database
235+
236+
Replace the contents of config/database.yml with the following:
237+
238+
```
239+
default: &default
240+
adapter: mysql2
241+
host: database
242+
username: ${DB_USER}
243+
password: ${DB_PASSWORD}
244+
pool: 5
245+
246+
development:
247+
<<: *default
248+
database: ${DB_NAME}
249+
250+
251+
test:
252+
<<: *default
253+
database: myapp_test
254+
```
255+
256+
[https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application](https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application)
257+
258+
[https://mariadb.com/kb/en/configuring-mariadb-with-option-files/](https://mariadb.com/kb/en/configuring-mariadb-with-option-files/)
259+
260+
#### Redis
261+
262+
add the configuration in the relevant config/environments/*.rb file:
263+
264+
```config.cache_store = :redis_cache_store, { url: 'redis' }```
265+
266+
[https://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-rediscachestore](https://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-rediscachestore)
267+
268+
### phpMyAdmin
269+
270+
You can add your own custom config.inc.php settings (such as Configuration Storage setup) by creating a file named config.user.inc.php with the various user defined settings in it, and then linking it into the container using:
271+
272+
```
273+
./phpmyadmin/config.user.inc.php
274+
```
275+
276+
You can also visit `https://example.com:9090` to access phpMyAdmin after starting the containers.
277+
278+
The first authorize screen(htpasswd;username or password) and phpmyadmin login screen the username and the password is the same as supplied in the `.env` file.
279+
280+
### backup
281+
282+
This will back up the all files and folders, once per day, and write it to ./backups with a filename like backup-2022-02-07T16-51-56.tar.gz
283+
284+
#### example for crontab file on the host machine
285+
286+
##### # old docker backup folder remove
287+
288+
```
289+
50 23 * * * find ${DIRECTORY_PATH}/backups/backup* -type f -mtime +1 | xargs rm
290+
```
291+
292+
##### # backup exclude rails, backups folders in ${DIRECTORY_PATH}
293+
294+
```
295+
00 01 * * * tar -czvf ${DIRECTORY_PATH}/backups/'backup-example.com-'$(date +"\%Y-\%m-\%dT\%H-\%M-\%S")'.tar.gz' --exclude='backups' ${DIRECTORY_PATH}
296+
```
297+
298+
[CronHowto](https://help.ubuntu.com/community/CronHowto)

backups/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore

certbot/.certbot.lock

Whitespace-only changes.

certbot/ssl-dhparam.pem

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-----BEGIN DH PARAMETERS-----
2+
MIIBCAKCAQEA3T1FEu1mdoEgqUL/v7OPEGd8yp+/2nUHyRFeyx9UQu7GXWMk7SSC
3+
ob/WE62HKtTiL3GskWJYh5HCPcBOETCWtbeib4xX4x/M7fzRU+io7hraIXPq3f1/
4+
/9KMljeQF8YqX913DU0WbeA8gJrpWEKSTiYkKBoS5K0AfgQDcDv+rHD8vOANfU/h
5+
YtR/Pjidl8TL/64fyWnGLn1l6VMzyYqgxGIlVX51fdwkO1KPpI+nLvURv7iXph3H
6+
WdpZl7wT1kcctjqH84MFBb4CotzUceY/+L3JOtUMkQbf68nB6Fwrx63+9IEYN9of
7+
0pyDWBhM9NbnJUHZsJEBq49T4FPlMJCiMwIBAg==
8+
-----END DH PARAMETERS-----

database/conf.d/z-mysql.cnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[mysql]

0 commit comments

Comments
 (0)