aboutsummaryrefslogtreecommitdiff
path: root/app/im/deploy/im.hcl
blob: 1902978615895d497b541b6be12f76189befc14b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
job "im" {
  datacenters = ["neptune"]
  type = "service"
  
  group "synapse" {
    count = 1

    network {
      port "http" {
        to = 8008
      }
    }

    ephemeral_disk {
      size    = 10000
    }

    restart {
      attempts = 10
      delay    = "60s"
    }

    task "restore-db" {
      lifecycle {
        hook = "prestart"
        sidecar = false
      }

      driver = "docker"
      config {
        image = "litestream/litestream:0.3.7"
        args = [
          "restore", "-config", "/etc/litestream.yml", "/ephemeral/homeserver.db"
        ]
        volumes = [
          "../alloc/data:/ephemeral",
          "secrets/litestream.yml:/etc/litestream.yml"
        ]
      }

      template {
        data = file("../config/litestream.yml")
        destination = "secrets/litestream.yml"
      }

      resources {
        memory = 1000
        cpu = 1000
      }
    }

    task "synapse" {
      driver = "docker"
      config {
        image = "lxpz/amd64_synapse:test7"
        ports = [ "http" ]

        command = "python"
        args = [
          "-m", "synapse.app.homeserver",
          "-n",
          "-c", "/etc/matrix-synapse/homeserver.yaml"
        ]

        volumes = [
          "secrets:/etc/matrix-synapse",
          "../alloc/data:/ephemeral",
        ]
      }

      template {
        data = file("../config/homeserver.yaml")
        destination = "secrets/homeserver.yaml"
      }

      template {
        data = file("../config/synapse.log.config.yaml")
        destination = "secrets/synapse.log.config.yaml"
      }

      template {
        data = "{{ key \"secrets/synapse/signing_key\" }}"
        destination = "secrets/signing_key"
      }

      resources {
        memory = 1500
        cpu = 1000
      }

      service {
        port = "http"
        tags = [
          "tricot matrix.home.adnab.me 100",
          "tricot matrix.home.adnab.me:443 100",
          "tricot-add-header Access-Control-Allow-Origin *",
        ]
        check {
          type = "http"
          path = "/"
          interval = "10s"
          timeout = "2s"
        }
      }
    }

    task "media-async-upload" {
      driver = "docker"

      config {
        image = "lxpz/amd64_synapse:test7"
        readonly_rootfs = true
        command = "/usr/local/bin/matrix-s3-async-sqlite"
        work_dir = "/ephemeral"
        volumes = [
          "../alloc/data:/ephemeral",
        ]
      }

      resources {
        cpu = 100
        memory = 200
      }

      template {
        data = <<EOH
AWS_ACCESS_KEY_ID={{ key "secrets/synapse/s3_access_key" | trimSpace }}
AWS_SECRET_ACCESS_KEY={{ key "secrets/synapse/s3_secret_key" | trimSpace }}
AWS_DEFAULT_REGION=garage-staging
EOH
        destination = "secrets/env"
        env = true
      }
    }

    task "replicate-db" {
      driver = "docker"
      config {
        image = "litestream/litestream:0.3.7"
        args = [
          "replicate", "-config", "/etc/litestream.yml"
        ]
        volumes = [
          "../alloc/data:/ephemeral",
          "secrets/litestream.yml:/etc/litestream.yml"
        ]
      }

      template {
        data = file("../config/litestream.yml")
        destination = "secrets/litestream.yml"
      }

      resources {
        memory = 500
        cpu = 100
      }
    }
  }
}