/
rockcraft.yaml
277 lines (276 loc) · 9.99 KB
/
rockcraft.yaml
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
name: discourse
summary: Discourse rock
description: Discourse OCI image for the Discourse charm
base: ubuntu@22.04
# renovate: base: ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2
run-user: _daemon_ # UID/GID 584792
license: Apache-2.0
version: "1.0"
platforms:
amd64:
parts:
tooling:
plugin: nil
overlay-packages:
- brotli
- g++
- gcc
- gettext-base
- gifsicle
- git
- imagemagick
- jhead
- jpegoptim
- libjpeg-turbo-progs
- libpq-dev
- libssl-dev
- libxml2-dev
- libxslt1-dev
- libyaml-dev
- libz-dev
- optipng
- pngquant
- postgresql-client
- postgresql-client-common
- redis-tools
- tzdata
- ubuntu-dev-tools
- zlib1g-dev
build-environment:
- ARCH: "x64"
- NODE_VERSION: "18.18.2"
- RAILS_ENV: "production"
- RUBY_INSTALL_VERSION: "0.9.2"
- RUBY_VERSION: "3.2.2"
- YARN_VERSION: "1.22.19"
override-build: |
node_uri="https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${ARCH}.tar.gz"
curl -Ls $node_uri | tar xzf - -C $CRAFT_OVERLAY/ --skip-old-files --no-same-owner --strip-components=1
yarn_uri="https://github.com/yarnpkg/yarn/releases/download/v${YARN_VERSION}/yarn-v${YARN_VERSION}.tar.gz"
curl -Ls $yarn_uri | tar xzf - -C $CRAFT_OVERLAY/ --skip-old-files --no-same-owner --strip-components=1
$CRAFT_OVERLAY/usr/bin/node $CRAFT_OVERLAY/usr/bin/npm install --verbose --prefix $CRAFT_OVERLAY/usr/local/ --global terser
$CRAFT_OVERLAY/usr/bin/node $CRAFT_OVERLAY/usr/bin/npm install --verbose --prefix $CRAFT_OVERLAY/usr/local/ --global svgo
ruby_install_uri="https://github.com/postmodern/ruby-install/releases/download/v${RUBY_INSTALL_VERSION}/ruby-install-${RUBY_INSTALL_VERSION}.tar.gz"
curl -fLO $ruby_install_uri
tar -xzvf ruby-install-${RUBY_INSTALL_VERSION}.tar.gz
cd ruby-install-${RUBY_INSTALL_VERSION}/
make install
ruby-install --system ruby $RUBY_VERSION
cp -pR /usr/local/ ${CRAFT_OVERLAY}/usr/
discourse:
after: [tooling]
plugin: dump
source: https://github.com/discourse/discourse.git
source-depth: 1
source-tag: v3.2.0
source-type: git
override-build: |
craftctl default
mkdir -p log
mkdir -p public/backups/default
mkdir -p public/uploads/default
mkdir -p srv/discourse/app/bin
mkdir -p srv/discourse/app/vendor/bundle
mkdir -p tmp/backups/default
touch log/production.log
touch log/unicorn-stderr.log
organize:
"*.*": srv/discourse/app/
"*": srv/discourse/app/
".*": srv/discourse/app/
bundler-config:
plugin: dump
after: [discourse]
source: bundler
organize:
"*": srv/discourse/app/.bundle/
discourse-rad-plugin:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/canonical/discourse-rad-plugin.git
source-commit: 7fe719abd459ab2d2736d6ad2ca7810b045dd154
source-depth: 1
organize:
"*": srv/discourse/app/plugins/discourse-rad-plugin/
discourse-solved:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-solved.git
source-commit: 526a44644a7b3f0c2a3ba4fc16e72f364e9fce6d
source-depth: 1
organize:
"*": srv/discourse/app/plugins/discourse-solved/
discourse-markdown-note:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/canonical-web-and-design/discourse-markdown-note.git
source-commit: f4426d5929de067f123659dc690e9438a324817a
source-depth: 1
organize:
"*": srv/discourse/app/plugins/markdown-note/
discourse-mermaid-theme-component:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-mermaid-theme-component.git
source-commit: 6fc85e72896b1933c8d2b12a0b34333db43c8cbe
source-depth: 1
organize:
"*": srv/discourse/app/plugins/discourse-mermaid-theme-component/
discourse-saml:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-saml.git
source-commit: 197b39978602e0ac6386c3e55ddc42f73efbfbce
source-depth: 1
override-build: |
craftctl default
grep -e ^gem plugin.rb >> Gemfile
organize:
"*": srv/discourse/app/plugins/discourse-saml/
discourse-prometheus:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-prometheus.git
source-commit: 831dba15659055361966e0c42e6b517b3d7b133b
source-depth: 1
override-build: |
craftctl default
grep -e ^gem plugin.rb >> Gemfile
organize:
"*": srv/discourse/app/plugins/discourse-prometheus/
discourse-data-explorer:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-data-explorer.git
source-commit: ebe71a7a138c856d88737eb11b5096a42d4fbaf3
source-depth: 1
organize:
"*": srv/discourse/app/plugins/discourse-data-explorer/
discourse-templates:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-templates.git
source-commit: bb410b2a7d84f4503a9fa8a1fbbe017d627348d8
source-depth: 1
organize:
"*": srv/discourse/app/plugins/discourse-templates/
discourse-calendar:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-calendar.git
source-commit: 84ef46a38cf02748ecacad16c5d9c6fec12dc8da
source-depth: 1
organize:
"*": srv/discourse/app/plugins/discourse-calendar/
discourse-gamification:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-gamification.git
source-commit: 5951fc573702090c0dc95b12d4aa3a053303bd63
source-depth: 1
organize:
"*": srv/discourse/app/plugins/discourse-gamification/
patches:
plugin: dump
after: [discourse]
source: patches
organize:
"*": srv/discourse/app/patches/
apply-patches:
plugin: nil
build-packages:
- git
after: [discourse, patches]
override-stage: |
git -C srv/discourse/app apply patches/lp1903695.patch
git -C srv/discourse/app apply patches/anonymize_user.patch
git -C srv/discourse/app apply patches/sigterm.patch
# The following is a fix for UglifierJS assets compilation
# https://github.com/lautis/uglifier/issues/127#issuecomment-352224986
sed -i 's/config.assets.js_compressor = :uglifier/config.assets.js_compressor = Uglifier.new(:harmony => true)/g' srv/discourse/app/config/environments/production.rb
sed -i '1s/^/require "uglifier"\n/' srv/discourse/app/config/environments/production.rb
scripts:
plugin: dump
source: scripts
organize:
"*": srv/scripts/
setup:
plugin: nil
after:
- apply-patches
- bundler-config
- discourse
- discourse-calendar
- discourse-data-explorer
- discourse-gamification
- discourse-markdown-note
- discourse-mermaid-theme-component
- discourse-prometheus
- discourse-rad-plugin
- discourse-saml
- discourse-solved
- discourse-templates
- patches
- scripts
- tooling
build-packages:
- git
- libpq-dev
- libssl-dev
override-prime: |
cd srv/discourse/app
gem install -n "bin" bundler -v 2.5.3
bin/bundle install
bin/bundle install --gemfile="plugins/discourse-calendar/Gemfile"
bin/bundle install --gemfile="plugins/discourse-data-explorer/Gemfile"
bin/bundle install --gemfile="plugins/discourse-gamification/Gemfile"
bin/bundle install --gemfile="plugins/discourse-prometheus/Gemfile"
bin/bundle install --gemfile="plugins/discourse-saml/Gemfile"
bin/bundle install --gemfile="plugins/discourse-solved/Gemfile"
bin/bundle install --gemfile="plugins/discourse-templates/Gemfile"
yarn install --immutable
discourse-precompile-assets:
plugin: nil
after: [apply-patches, setup]
build-packages:
- redis-tools
- postgresql-all
- postgresql-client
build-snaps:
- redis
override-prime: |
systemctl start postgresql
cd srv/discourse/app
su - postgres -c "psql -c \"CREATE DATABASE discourse;\"" || echo "Could not create database, maybe it already exists."
su - postgres -c "psql -c \"CREATE USER discourse WITH PASSWORD 'discourse';\"" || echo "Could not create user, maybe it already exists."
su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE discourse TO discourse;\""
PATH=$PATH:${CRAFT_PRIME}/usr/bin:${CRAFT_PRIME}/usr/local/bin RAILS_ENV=production DISCOURSE_DB_HOST=127.0.0.1 DISCOURSE_DB_PASSWORD=discourse bundle exec rake assets:precompile
# Fix the symbolic links.
find . -lname "${CRAFT_PRIME}/srv/discourse/*" -exec bash -c 'ln -snf "$(readlink "$1" | sed "s~${CRAFT_PRIME}~~")" "$1" ' sh {} \;
perms:
plugin: nil
after: [tooling, discourse, setup, discourse-precompile-assets]
override-prime: |
chown -R 584792:584792 srv/discourse
chown -R 584792:584792 srv/scripts
mkdir -p var/lib/pebble/default/.cache
mkdir -p var/lib/pebble/default/.config
mkdir -p var/lib/pebble/default/.local
mkdir -p var/lib/pebble/default/.npm
mkdir -p var/lib/pebble/default/.yarn
touch var/lib/pebble/default/.yarnrc
chown -R 584792:584792 var/lib/pebble/default/.cache
chown -R 584792:584792 var/lib/pebble/default/.config
chown -R 584792:584792 var/lib/pebble/default/.local
chown -R 584792:584792 var/lib/pebble/default/.npm
chown -R 584792:584792 var/lib/pebble/default/.yarn
chown 584792:584792 var/lib/pebble/default/.yarnrc
checks:
discourse-setup-completed:
override: replace
level: ready
threshold: 1
exec:
command: ls /run/discourse-k8s-operator/setup_completed