Skip to content

Commit 368e771

Browse files
authored
Merge pull request #5 from ndrean/main
change csp rules ofr fly.io deploy
2 parents 0582788 + 50b121d commit 368e771

File tree

7 files changed

+133
-5
lines changed

7 files changed

+133
-5
lines changed

.github/workflows/fly-deploy.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
2+
3+
name: Fly Deploy
4+
on:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
deploy:
10+
name: Deploy app
11+
runs-on: ubuntu-latest
12+
concurrency: deploy-group # optional: ensure only one action runs at a time
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: superfly/flyctl-actions/setup-flyctl@master
16+
- run: flyctl deploy --remote-only
17+
env:
18+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

Dockerfile

+15-4
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ FROM ${BUILDER_IMAGE} AS builder
2222

2323
# install build dependencies
2424
RUN apt-get update -y && apt-get install -y \
25-
build-essential \
25+
build-essential wget \
2626
git \
2727
curl \
2828
&& curl -sL https://deb.nodesource.com/setup_22.x | bash - && \
2929
apt-get install -y \
3030
nodejs && \
31-
apt-get clean && rm -f /var/lib/apt/lists/*_* && \
32-
node --version && \
33-
npm --version
31+
apt-get clean && rm -f /var/lib/apt/lists/*_*
32+
33+
# ARG LITESTREAM_VERSION=0.3.13
34+
# Install litestream
35+
# RUN wget https://github.com/benbjohnson/litestream/releases/download/v${LITESTREAM_VERSION}/litestream-v${LITESTREAM_VERSION}-linux-amd64.deb \
36+
# && dpkg -i litestream-v${LITESTREAM_VERSION}-linux-amd64.deb
3437

3538
RUN npm install -g pnpm
3639
RUN pnpm self-update
@@ -117,9 +120,17 @@ RUN mkdir -p /app/data && \
117120
chmod -R 777 /app/data && \
118121
chown nobody /app
119122

123+
# Copy Litestream binary from build stage
124+
COPY --from=builder /usr/bin/litestream /usr/bin/litestream
125+
COPY litestream.sh /app/bin/litestream.sh
126+
COPY config/litestream.yml /etc/litestream.yml
127+
120128
USER nobody
121129

122130
EXPOSE 4000
131+
# Run litestream script as entrypoint
132+
ENTRYPOINT ["/bin/bash", "/app/bin/litestream.sh"]
133+
123134
CMD ["/bin/sh", "-c", "mkdir -p /app/data && /app/bin/server"]
124135

125136

config/litestream.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This is the configuration file for litestream.
2+
#
3+
# For more details, see: https://litestream.io/reference/config/
4+
#
5+
dbs:
6+
- path: $DATABASE_PATH
7+
replicas:
8+
- type: s3
9+
endpoint: $AWS_ENDPOINT_URL_S3
10+
bucket: $BUCKET_NAME
11+
path: litestream${DATABASE_PATH}
12+
access-key-id: $AWS_ACCESS_KEY_ID
13+
secret-access-key: $AWS_SECRET_ACCESS_KEY
14+
region: $AWS_REGION

fly.toml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# fly.toml app configuration file generated for solidyjs-lively-pine-4375 on 2025-03-24T15:51:50-05:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'solidyjs-lively-pine-4375'
7+
primary_region = 'bog'
8+
kill_signal = 'SIGTERM'
9+
10+
[build]
11+
12+
[env]
13+
DATABASE_PATH = '/mnt/name/name.db'
14+
PHX_HOST = 'solidyjs-lively-pine-4375.fly.dev'
15+
PORT = '8080'
16+
17+
[[mounts]]
18+
source = 'name'
19+
destination = '/mnt/name'
20+
auto_extend_size_threshold = 80
21+
auto_extend_size_increment = '1GB'
22+
auto_extend_size_limit = '10GB'
23+
24+
[http_service]
25+
internal_port = 8080
26+
force_https = true
27+
auto_stop_machines = 'stop'
28+
auto_start_machines = true
29+
min_machines_running = 0
30+
processes = ['app']
31+
32+
[http_service.concurrency]
33+
type = 'connections'
34+
hard_limit = 1000
35+
soft_limit = 1000
36+
37+
[[vm]]
38+
memory = '512mb'
39+
cpu_kind = 'shared'
40+
cpus = 1

lib/solidyjs/release.ex

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
defmodule Solidyjs.Release do
2+
@moduledoc """
3+
Used for executing DB release tasks when run in production without Mix
4+
installed.
5+
"""
6+
@app :solidyjs
7+
8+
def migrate do
9+
load_app()
10+
11+
for repo <- repos() do
12+
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
13+
end
14+
end
15+
16+
def rollback(repo, version) do
17+
load_app()
18+
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
19+
end
20+
21+
defp repos do
22+
Application.fetch_env!(@app, :ecto_repos)
23+
end
24+
25+
defp load_app do
26+
Application.load(@app)
27+
end
28+
end

lib/solidyjs_web/router.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule SolidyjsWeb.Router do
33

44
@csp (case MIX_ENV do
55
:prod ->
6-
"require-trusted-types-for 'script'; script-src 'self' 'wasm-unsafe-eval'; object-src 'none'; connect-src http://localhost:* ws://localhost:* https://api.maptiler.com/; img-src 'self' data: https://*.maptiler.com/ https://api.maptiler.com/; worker-src 'self' blob:; style-src 'self' 'unsafe-inline'; default-src 'self'; frame-ancestors 'none'; base-uri 'self'"
6+
"require-trusted-types-for 'script'; script-src 'self' 'wasm-unsafe-eval'; object-src 'none'; connect-src 'self' wss://solidyjs-lively-pine-4375.fly.dev ws://solidyjs-lively-pine-4375.fly.dev https://api.maptiler.com/; img-src 'self' data: https://*.maptiler.com/ https://api.maptiler.com/; worker-src 'self' blob:; style-src 'self' 'unsafe-inline'; default-src 'self'; frame-ancestors 'none'; base-uri 'self'"
77

88
_ ->
99
"script-src 'self' 'wasm-unsafe-eval'; object-src 'none'; connect-src http://localhost:* ws://localhost:* https://api.maptiler.com/; img-src 'self' data: https://*.maptiler.com/ https://api.maptiler.com/; worker-src 'self' blob:; style-src 'self' 'unsafe-inline'; default-src 'self'; frame-ancestors 'none'; base-uri 'self'"

litestream.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# If db doesn't exist, try restoring from object storage
5+
if [ ! -f "$DATABASE_PATH" ] && [ -n "$BUCKET_NAME" ]; then
6+
litestream restore -if-replica-exists "$DATABASE_PATH"
7+
fi
8+
9+
# Migrate database
10+
/app/bin/migrate
11+
12+
# Launch application
13+
if [ -n "$BUCKET_NAME" ]; then
14+
litestream replicate -exec "${*}"
15+
else
16+
exec "${@}"
17+
fi

0 commit comments

Comments
 (0)