]> Untitled Git - lemmy.git/blob - .drone.yml
Adding TOTP / 2FA to lemmy (#2741)
[lemmy.git] / .drone.yml
1 ---
2 kind: pipeline
3 name: amd64
4
5 platform:
6   os: linux
7   arch: amd64
8
9 steps:
10
11   # use minimum supported rust version for most steps
12   - name: prepare repo
13     image: alpine:3
14     commands:
15       - apk add git
16       - git fetch --tags
17       - git submodule init
18       - git submodule update --recursive --remote
19
20   - name: cargo fmt
21     image: clux/muslrust:1.67.0
22     environment:
23       # store cargo data in repo folder so that it gets cached between steps
24       CARGO_HOME: .cargo
25     commands:
26       # need make existing toolchain available
27       - cp ~/.cargo . -r
28       - rustup toolchain install nightly
29       - rustup component add rustfmt --toolchain nightly
30       - cargo +nightly fmt -- --check
31
32   # check each package to make sure they compile with default features.
33   # this is required for crates.io
34   - name: cargo check
35     image: clux/muslrust:1.67.0
36     environment:
37       CARGO_HOME: .cargo
38     commands:
39       - cargo check --package lemmy_utils
40       - cargo check --package lemmy_db_schema
41       - cargo check --package lemmy_db_views
42       - cargo check --package lemmy_db_views_actor
43       - cargo check --package lemmy_db_views_moderator
44       - cargo check --package lemmy_api_common
45       - cargo check --package lemmy_api
46       - cargo check --package lemmy_api_crud
47       - cargo check --package lemmy_apub
48       - cargo check --package lemmy_routes
49       - cargo check --workspace
50       - cargo check --workspace --features console
51       # disabled because it takes too long with pict-rs
52       #- cargo check --workspace --all-features
53
54   - name: cargo clippy
55     image: clux/muslrust:1.67.0
56     environment:
57       CARGO_HOME: .cargo
58     commands:
59         # latest rust for clippy to get extra checks
60         # when adding new clippy lints, make sure to also add them in scripts/fix-clippy.sh
61       - rustup component add clippy
62       - cargo clippy --workspace --tests --all-targets --features console --
63           -D warnings -D deprecated -D clippy::perf -D clippy::complexity 
64           -D clippy::style -D clippy::correctness -D clippy::suspicious
65           -D clippy::dbg_macro -D clippy::inefficient_to_string 
66           -D clippy::items-after-statements -D clippy::implicit_clone 
67           -D clippy::wildcard_imports -D clippy::cast_lossless 
68           -D clippy::manual_string_new -D clippy::redundant_closure_for_method_calls 
69           -D clippy::unused_self
70           -A clippy::uninlined_format_args
71           -D clippy::get_first
72       - cargo clippy --workspace --features console -- 
73         -D clippy::unwrap_used
74         -D clippy::indexing_slicing
75
76   - name: lemmy_api_common doesnt depend on diesel
77     image: clux/muslrust:1.67.0
78     environment:
79       CARGO_HOME: .cargo
80     commands:
81       - "! cargo tree -p lemmy_api_common --no-default-features -i diesel"
82
83   - name: check defaults.hjson updated
84     image: clux/muslrust:1.67.0
85     environment:
86       CARGO_HOME: .cargo
87     commands:
88       - export LEMMY_CONFIG_LOCATION=./config/config.hjson
89       - ./scripts/update_config_defaults.sh config/defaults_current.hjson
90       - diff config/defaults.hjson config/defaults_current.hjson
91
92   - name: cargo test
93     image: clux/muslrust:1.67.0
94     environment:
95       LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
96       RUST_BACKTRACE: 1
97       RUST_TEST_THREADS: 1
98       CARGO_HOME: .cargo
99     commands:
100       - export LEMMY_CONFIG_LOCATION=../../config/config.hjson
101       - cargo test --workspace --no-fail-fast
102
103   - name: cargo build
104     image: clux/muslrust:1.67.0
105     environment:
106       CARGO_HOME: .cargo
107     commands:
108       - cargo build
109       - mv target/x86_64-unknown-linux-musl/debug/lemmy_server target/lemmy_server
110
111   - name: run federation tests
112     image: node:alpine
113     environment:
114       LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432
115       DO_WRITE_HOSTS_FILE: 1
116     commands:
117       - apk add bash curl postgresql-client
118       - bash api_tests/prepare-drone-federation-test.sh
119       - cd api_tests/
120       - yarn
121       - yarn api-test
122
123   - name: nightly build
124     image: plugins/docker
125     settings:
126       dockerfile: docker/Dockerfile
127       build_args: RUST_RELEASE_MODE=release
128       username:
129         from_secret: docker_username
130       password:
131         from_secret: docker_password
132       repo: dessalines/lemmy
133       add_host: github.com:140.82.112.3,static.crates.io:18.154.227.73,crates.io:108.138.64.68,dl-cdn.alpinelinux.org:146.75.30.133
134       tags:
135         - dev
136     when:
137       event:
138         - cron
139
140   - name: publish release docker image
141     image: plugins/docker
142     settings:
143       dockerfile: docker/Dockerfile
144       build_args: RUST_RELEASE_MODE=release
145       username:
146         from_secret: docker_username
147       password:
148         from_secret: docker_password
149       repo: dessalines/lemmy
150       add_host: github.com:140.82.112.3,static.crates.io:18.154.227.73,crates.io:108.138.64.68,dl-cdn.alpinelinux.org:146.75.30.133
151       auto_tag: true
152       auto_tag_suffix: linux-amd64
153     when:
154       ref:
155         - refs/tags/*
156
157   - name: publish release docker manifest
158     image: plugins/manifest
159     settings:
160       username:
161         from_secret: docker_username
162       password:
163         from_secret: docker_password
164       target: "dessalines/lemmy:${DRONE_TAG}"
165       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
166       platforms:
167         - linux/amd64
168         - linux/arm64
169       ignore_missing: true
170     when:
171       ref:
172         - refs/tags/*
173
174   - name: publish latest release docker manifest
175     image: plugins/manifest
176     settings:
177       username:
178         from_secret: docker_username
179       password:
180         from_secret: docker_password
181       target: "dessalines/lemmy:latest"
182       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
183       platforms:
184         - linux/amd64
185         - linux/arm64
186       ignore_missing: true
187     when:
188       ref:
189         - refs/tags/*
190
191   # using https://github.com/pksunkara/cargo-workspaces
192   - name: publish to crates.io
193     image: clux/muslrust:1.67.0
194     environment:
195       CARGO_TOKEN:
196         from_secret: cargo_api_token
197     commands:
198       - cargo install cargo-workspaces
199       - cp -r migrations crates/db_schema/
200       - cargo login "$CARGO_TOKEN"
201       - cargo workspaces publish --from-git --allow-dirty --no-verify --allow-branch "${DRONE_TAG}" --yes custom "${DRONE_TAG}"
202     when:
203       ref:
204         - refs/tags/*
205
206   - name: Notify on failure
207     image: alpine:3
208     commands: 
209       - apk add curl
210       - "curl -d'Drone build failed: ${DRONE_BUILD_LINK}' ntfy.sh/lemmy_drone_ci"
211     when:
212       status:
213         - failure
214
215   - name: Notify on tag deploy
216     image: alpine:3
217     commands: 
218       - apk add curl
219       - "curl -d'lemmy:${DRONE_TAG} deployed' ntfy.sh/lemmy_drone_ci"
220     when:
221       ref:
222         - refs/tags/*
223
224 services:
225   - name: database
226     image: postgres:15-alpine
227     environment:
228       POSTGRES_USER: lemmy
229       POSTGRES_PASSWORD: password
230
231 ---
232 kind: pipeline
233 name: arm64
234
235 platform:
236   os: linux
237   arch: arm64
238
239 steps:
240
241   - name: prepare repo
242     image: rust:1.57-slim
243     user: root
244     commands:
245       - apt update
246       - apt install --no-install-recommends --yes git
247       - git fetch --tags
248       - git submodule init
249       - git submodule update --recursive --remote
250
251   # TODO temporarily disable arm tests
252   # - name: cargo test
253   #   image: rust:1.57-slim
254   #   environment:
255   #     LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
256   #     LEMMY_CONFIG_LOCATION: ../../config/config.hjson
257   #     RUST_BACKTRACE: 1
258   #     RUST_TEST_THREADS: 1
259   #   commands:
260   #     - apt-get update
261   #     - apt-get -y install --no-install-recommends postgresql-client libssl-dev pkg-config libpq-dev
262   #     - cargo test --workspace --no-fail-fast
263   #     - cargo build
264
265   # TODO temporarily disable arm tests
266   # Using Debian here because there seems to be no official Alpine-based Rust docker image for ARM.
267   # - name: cargo build
268   #   image: rust:1.57-slim
269   #   commands:
270   #     - apt-get update
271   #     - apt-get -y install --no-install-recommends libssl-dev pkg-config libpq-dev
272   #     - cargo build
273   #     - mv target/debug/lemmy_server target/lemmy_server
274
275   # TODO temporarily disable arm tests
276   # - name: run federation tests
277   #   image: node:16-slim
278   #   environment:
279   #     LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432
280   #     DO_WRITE_HOSTS_FILE: 1
281   #   commands:
282   #     - mkdir -p /usr/share/man/man1 /usr/share/man/man7
283   #     - apt-get update
284   #     - apt-get -y install --no-install-recommends bash curl libssl-dev pkg-config libpq-dev postgresql-client libc6-dev
285   #     - bash api_tests/prepare-drone-federation-test.sh
286   #     - cd api_tests/
287   #     - yarn
288   #     - yarn api-test
289
290   - name: publish release docker image
291     image: plugins/docker
292     settings:
293       dockerfile: docker/Dockerfile.arm
294       username:
295         from_secret: docker_username
296       password:
297         from_secret: docker_password
298       repo: dessalines/lemmy
299       auto_tag: true
300       auto_tag_suffix: linux-arm64
301     when:
302       ref:
303         - refs/tags/*
304
305   - name: publish release docker manifest
306     image: plugins/manifest
307     settings:
308       username:
309         from_secret: docker_username
310       password:
311         from_secret: docker_password
312       target: "dessalines/lemmy:${DRONE_TAG}"
313       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
314       platforms:
315         - linux/amd64
316         - linux/arm64
317       ignore_missing: true
318     when:
319       ref:
320         - refs/tags/*
321
322   - name: publish latest release docker manifest
323     image: plugins/manifest
324     settings:
325       username:
326         from_secret: docker_username
327       password:
328         from_secret: docker_password
329       target: "dessalines/lemmy:latest"
330       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
331       platforms:
332         - linux/amd64
333         - linux/arm64
334       ignore_missing: true
335     when:
336       ref:
337         - refs/tags/*
338
339 # TODO temporarily disable arm tests
340 # services:
341 #   - name: database
342 #     image: postgres:12-alpine
343 #     environment:
344 #       POSTGRES_USER: lemmy
345 #       POSTGRES_PASSWORD: password