Add docker migration guide
[akkoma] / docs / docs / installation / migrating_to_docker_en.md
1 # Migrating to a Docker Installation
2
3 If you for any reason wish to migrate a source or OTP install to a docker one,
4 this guide is for you.
5
6 You have a few options - your major one will be whether you want to keep your
7 reverse-proxy setup from before.
8
9 You probably should, in the first instance.
10
11 ### Prepare the system
12
13 * Install docker and docker-compose
14 * [Docker](https://docs.docker.com/engine/install/)
15 * [Docker-compose](https://docs.docker.com/compose/install/)
16 * This will usually just be a repository installation and a package manager invocation.
17
18 === "Source"
19 ```bash
20 git pull
21 ```
22
23 === "OTP"
24 Clone the akkoma repository
25
26 ```bash
27 git clone https://akkoma.dev/AkkomaGang/akkoma.git -b stable
28 cd akkoma
29 ```
30
31 ### Back up your old database
32
33 Change the database name as needed
34
35 ```bash
36 pg_dump -d akkoma_prod --format c > akkoma_backup.sql
37 ```
38
39 ### Getting your static files in the right place
40
41 This will vary by every installation. Copy your `instance` directory to `instance/` in
42 the akkoma source directory - this is where the docker container will look for it.
43
44 For *most* from-source installs it'll already be there.
45
46 And the same with `uploads`, make sure your uploads (if you have them on disk) are
47 located at `uploads/` in the akkoma source directory.
48
49 If you have them on a different disk, you will need to mount that disk into the docker-compose file,
50 with an entry that looks like this:
51
52 ```yaml
53 akkoma:
54 volumes:
55 - .:/opt/akkoma # This should already be there
56 - type: bind
57 source: /path/to/your/uploads
58 target: /opt/akkoma/uploads
59 ```
60
61 ### Set up basic configuration
62
63 ```bash
64 cp docker-resources/env.example .env
65 echo "DOCKER_USER=$(id -u):$(id -g)" >> .env
66 ```
67
68 This probably won't need to be changed, it's only there to set basic environment
69 variables for the docker-compose file.
70
71 === "From source"
72
73 You probably won't need to change your config. Provided your `config/prod.secret.exs` file
74 is still there, you're all good.
75
76 === "OTP"
77 ```bash
78 cp /etc/akkoma/config.exs config/prod.secret.exs
79 ```
80
81 **BOTH**
82
83 Set the following config in `config/prod.secret.exs`:
84 ```elixir
85 config :pleroma, Pleroma.Web.Endpoint,
86 ...,
87 http: [ip: {0, 0, 0, 0}, port: 4000]
88
89 config :pleroma, Pleroma.Repo,
90 ...,
91 username: "akkoma",
92 password: "akkoma",
93 database: "akkoma",
94 hostname: "db"
95 ```
96
97 ### Building the container
98
99 The container provided is a thin wrapper around akkoma's dependencies,
100 it does not contain the code itself. This is to allow for easy updates
101 and debugging if required.
102
103 ```bash
104 ./docker-resources/build.sh
105 ```
106
107 This will generate a container called `akkoma` which we can use
108 in our compose environment.
109
110 ### Setting up the docker resources
111
112 ```bash
113 # These won't exist if you're migrating from OTP
114 rm -rf deps
115 rm -rf _build
116 ```
117
118 ```bash
119 mkdir pgdata
120 ./docker-resources/manage.sh mix deps.get
121 ./docker-resources/manage.sh mix compile
122 ```
123
124 ### Setting up the database
125
126 Now we can import our database to the container.
127
128 ```bash
129 docker-compose run --rm --user akkoma -d db
130 docker-compose run --rm akkoma pg_restore -v -U akkoma -j $(grep -c ^processor /proc/cpuinfo) -d akkoma -h db akkoma_backup.sql
131 ```
132
133 ### Reverse proxies
134
135 If you're just reusing your old proxy, you may have to uncomment the line in
136 the docker-compose file under `ports`. You'll find it.
137
138 Otherwise, you can use the same setup as the [docker installation guide](./docker_en.md#reverse-proxies).
139
140 ### Let's go
141
142 ```bash
143 docker-compose up -d
144 ```
145
146 You should now be at the same point as you were before, but with a docker install.
147
148 {! installation/frontends.include !}
149
150 See the [docker installation guide](./docker_en.md) for more information on how to
151 update.
152
153 #### Further reading
154
155 {! installation/further_reading.include !}
156
157 {! support.include !}
158