Repository navigation
285 lines (236 loc) · 7.86 KB
/
Copy pathelixir.yml
File metadata and controls
285 lines (236 loc) · 7.86 KB
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
278
279
280
281
282
283
284
285
---
name: elixir
"on":
pull_request:
push:
branches: [main]
env:
MIX_ENV: test
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DATABASE_TEST_NAME: textbin_test
OTP_VERSION: "28.5"
ELIXIR_VERSION: "1.20"
jobs:
lint:
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- name: Cache Mix dependencies
uses: actions/cache@v4
with:
path: |
deps
_build
key: mix-lint-${{ runner.os }}-${{ hashFiles('mix.lock') }}
restore-keys: |
mix-lint-${{ runner.os }}-
mix-${{ runner.os }}-
- name: Install Hex and Rebar
run: |
mix local.hex --force
mix local.rebar --force
- name: Install dependencies
run: mix deps.get
- name: Linter
run: mix credo
format:
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- name: Cache Mix dependencies
uses: actions/cache@v4
with:
path: |
deps
_build
key: mix-format-${{ runner.os }}-${{ hashFiles('mix.lock') }}
restore-keys: |
mix-format-${{ runner.os }}-
mix-${{ runner.os }}-
- name: Install Hex and Rebar
run: |
mix local.hex --force
mix local.rebar --force
- name: Install dependencies
run: mix deps.get
- name: Check formatting
run: mix format --check-formatted
test:
name: "Test (store: ${{ matrix.storage-backend }})"
runs-on: blacksmith-2vcpu-ubuntu-2404
strategy:
fail-fast: false
matrix:
storage-backend: [memory, local, s3]
services:
postgres:
image: postgres:17-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: textbin_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres -d textbin_test"
--health-interval 5s
--health-timeout 5s
--health-retries 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
- name: Cache Mix dependencies
uses: actions/cache@v4
with:
path: |
deps
_build
key: >-
mix-test-${{ matrix.storage-backend }}-${{ hashFiles('mix.lock') }}
restore-keys: |
mix-test-${{ matrix.storage-backend }}-
mix-test-
mix-
- name: Install Hex and Rebar
run: |
mix local.hex --force
mix local.rebar --force
- name: Install dependencies
run: mix deps.get
- name: Compile
run: mix compile --warnings-as-errors
- name: Check unused dependencies
run: mix deps.unlock --check-unused
- name: Start SeaweedFS
if: matrix.storage-backend == 's3'
run: |
docker compose up -d object-storage
for attempt in $(seq 1 30); do
if curl --silent --show-error \
--output /dev/null http://127.0.0.1:8333/; then
exit 0
fi
sleep 1
done
docker compose logs object-storage
exit 1
- name: Run tests with ${{ matrix.storage-backend }} storage
env:
STORAGE_BACKEND: ${{ matrix.storage-backend }}
TEXTBIN_STORAGE_PATH: ${{ runner.temp }}/textbin-storage
S3_ENDPOINT: http://localhost:8333
S3_BUCKET: textbin
S3_REGION: us-east-1
S3_ACCESS_KEY_ID: textbin
S3_SECRET_ACCESS_KEY: textbin-development-secret
run: |
if [ "$STORAGE_BACKEND" = "memory" ]; then
unset TEXTBIN_STORAGE_BACKEND
else
export TEXTBIN_STORAGE_BACKEND="$STORAGE_BACKEND"
fi
mix test
container:
name: Production container
runs-on: blacksmith-2vcpu-ubuntu-2404
services:
postgres:
image: postgres:17-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${{ env.DATABASE_PASSWORD }}
POSTGRES_DB: textbin_container_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres -d textbin_container_test"
--health-interval 5s
--health-timeout 5s
--health-retries 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build production image
run: docker build --tag textbin:ci .
- name: Verify runtime contract
run: |
test "$(docker image inspect textbin:ci --format '{{.Config.User}}')" = "textbin"
test "$(docker image inspect textbin:ci --format '{{json .Config.Volumes}}')" = "null"
docker run --rm --entrypoint sh textbin:ci -c '
test "$(id -u)" = "1000"
test "$(id -g)" = "1000"
test -x /app/bin/textbin
test -x /app/bin/migrate
touch /var/lib/textbin/pastes/.write-test
touch /var/lib/textbin/uploads/.write-test
'
- name: Run release migrations
run: |
secret_key_base=$(openssl rand -hex 64)
docker run --rm --network host \
-e DATABASE_URL="ecto://${DATABASE_USER}:${DATABASE_PASSWORD}@localhost:5432/textbin_container_test" \
-e SECRET_KEY_BASE="$secret_key_base" \
-e PHX_HOST=localhost \
textbin:ci /app/bin/migrate
- name: Smoke test HTTP and direct TLS
run: |
tls_dir="${RUNNER_TEMP}/textbin-tls"
mkdir -p "$tls_dir"
openssl req -x509 -newkey rsa:2048 -sha256 -nodes -days 1 \
-subj '/CN=localhost' \
-addext 'subjectAltName=DNS:localhost' \
-keyout "$tls_dir/key.pem" \
-out "$tls_dir/cert.pem"
# The ephemeral test key must be readable by the image's UID 1000.
chmod 755 "$tls_dir"
chmod 644 "$tls_dir/cert.pem" "$tls_dir/key.pem"
secret_key_base=$(openssl rand -hex 64)
container_name=textbin-container-smoke
cleanup() {
docker logs "$container_name" || true
docker rm --force "$container_name" || true
}
trap cleanup EXIT
docker run --detach --name "$container_name" --network host \
--mount "type=bind,src=$tls_dir,dst=/run/secrets/textbin,readonly" \
-e DATABASE_URL="ecto://${DATABASE_USER}:${DATABASE_PASSWORD}@localhost:5432/textbin_container_test" \
-e SECRET_KEY_BASE="$secret_key_base" \
-e PHX_HOST=localhost \
-e PORT=4100 \
-e HTTPS_PORT=4443 \
-e TLS_CERT_PATH=/run/secrets/textbin/cert.pem \
-e TLS_KEY_PATH=/run/secrets/textbin/key.pem \
textbin:ci
ready=false
for attempt in $(seq 1 30); do
if curl --fail --silent --show-error \
--resolve localhost:4443:127.0.0.1 \
--cacert "$tls_dir/cert.pem" \
--output /dev/null https://localhost:4443/; then
ready=true
break
fi
sleep 1
done
test "$ready" = "true"
curl --fail --silent --show-error --output /dev/null http://127.0.0.1:4100/