Skip to content

Commit ec21dcf

Browse files
authored
Create upgrade-guide.md
1 parent 04a4611 commit ec21dcf

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

docs/upgrade-guide.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Upgrading guide
2+
3+
Here we will try to cover all aspects we faced in a real production environment when migrating from the previous version of this project to the newst version.
4+
5+
## From v0.4 to v0.5
6+
7+
The version v0.5 was a big step into automation. We 'conquer the world'!
8+
9+
> I update one of the production server and got a _96 seconds_ of downtime, with no complaint from clients.
10+
> Some of them did not even notice, but all were advised about the update and the possible downtime in case of failure.
11+
12+
> If you can not afford this downtime there is a couple way around on this but you will need
13+
a couple things... new server (temporary), set a dns rules to create the new certificates
14+
copy all files to the new server and do the following, after all is ready, redirect the dns
15+
to the new server and than copy the temp server to the production, fire all services, test
16+
and redirect the dns to the new server. Be aware that changes made during this proccess might
17+
need to be updated in the containers when syncing files from one server to another.
18+
19+
So, let's go. First thing first!
20+
21+
1. Backup EVERYTHING! I would suggest backup in the server and somewhere else (not in the server)
22+
23+
2. Update the git repo with the new version (:warning:)
24+
25+
2.1 Copy _docker-compose.yml_ (or the _docker-compose-multiple-networks.yml_ if you used this option) and _.env_ file
26+
27+
```bash
28+
$ cp docker-compose.yml docker-compose-old.yml
29+
$ cp .env .env-old
30+
```
31+
32+
> We will use this do stop the current services
33+
34+
2.2 Reset all changes in the repo
35+
36+
This is required to update to the latest version
37+
38+
```bash
39+
$ git reset --hard
40+
```
41+
42+
2.3 Checkout master
43+
44+
```bash
45+
$ git checkout master
46+
```
47+
48+
2.4 Set the **basescript** submodule
49+
50+
If you notice the submodule folder used in this project ([basescript](https://github.com/evertramos/basescript/))
51+
is present in the master branch we just checkout, but it is empty, so we need to fix it (init and update).
52+
53+
```bash
54+
$ cd basescript
55+
$ git submodule init
56+
$ git submodule update
57+
```
58+
59+
> The _basescript_ folder should not be empty after the commands above
60+
61+
3. Run the _fresh-start.sh_ script (:construction:)
62+
63+
Here we will run the _fresh-start.sh_ script in order to create all new settings that we will use.
64+
Please do it carefully. You might use different names for proxy services.
65+
66+
```bash
67+
$ cd bin
68+
$ ./fresh-start.sh
69+
```
70+
71+
In most cases you will get the following _'error'_, which is expected:
72+
73+
![fresh-start-expected-error](https://user-images.githubusercontent.com/905951/113016796-33aaa080-9155-11eb-845d-aa712294236d.png)
74+
75+
The error above is related to port binding, once port 80 is already binded to the current nginx-proxy container.
76+
77+
> [IMPORTANT] If you use the *same service name* for all containers and the same network name you might not receive the error above
78+
> and you should be ready to go at this point. Check the your running sites at the browser to see if everything is up and running.
79+
80+
⚠️ if you do not get the error above and your sites are NOT working, you might checkthe network name and go for the next item.
81+
82+
4. Adding the running containers to the new network
83+
84+
If you keep the same network name you might skip this item, but if not, you must add all running containers to the new network
85+
created by the _fresh-start.sh_ script.
86+
87+
```bash
88+
$ docker network connect [YOUR_NEW_NETWORK_NAME] [CONTAINER_NAME]
89+
```
90+
91+
> Run the command above for all containers connected to the proxy and remember to update the network name in the docker-compose file
92+
> for the all sites
93+
94+
5. Restart proxy with new service
95+
96+
At this point all sites should be still up and running, so keep it cool and let's see if all will work as expected.
97+
98+
After all containers are connected to the new proxy network (if the case) you will stop the current proxy services and start the new one.
99+
We did it in one command line to reduce the downtime.
100+
101+
```bash
102+
$ docker-compose --file docker-compose-old.yml down && docker-compose up -d
103+
```
104+
105+
Check your sites to see if it is all running, if some of them are not working, you might check the letsencrypt container logs to see if
106+
there was a problem issuing new certificates.
107+
108+
If something else happen and you must reverse it quickly just follow the next step. But try to check the logs first, it might take a few
109+
minutes to fire new certificates with Let's Encrypt so, depending on the quantity of sites you are running in your server it might take
110+
some time to issue it all.
111+
112+
6. Reverting to the old proxy
113+
114+
You can retore backup files and start the same exact environmen you had previously this upgrade guide, but there is a quicker way to restore your sites.
115+
Just run the following:
116+
117+
```bash
118+
$ docker-compose down && docker-compose --file docker-compose-old.yml --env-file .env-old up -d
119+
```
120+
121+
> The command above will stop the new version and fire the previous version of your proxy, so, after this command evertyhing should 'be back to normal'
122+
> as it was before the update, but keep in mind to find the errors if they occured and update it.
123+
124+
7. Clean up
125+
126+
After having all work done you might remove unused file such as:
127+
128+
129+
```bash
130+
$ rm docker-compose-old.yml .env-old
131+
```
132+
133+
> If you get any erros when updating please post on the [**upgrade discussion**](https://github.com/evertramos/basescript/discussions/5) (avoid creating new issues).

0 commit comments

Comments
 (0)