Skip to content

Commit e6b8839

Browse files
committed
add fly.io deployment
1 parent 9cef1fb commit e6b8839

File tree

8 files changed

+104
-17
lines changed

8 files changed

+104
-17
lines changed

.github/workflows/fly-deploy.yml

Lines changed: 18 additions & 0 deletions
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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,10 @@ WORKDIR /usr/src/app
66

77
COPY . .
88
RUN cargo build --bin monolith --release
9+
ADD https://github.com/benbjohnson/litestream/releases/download/v0.3.8/litestream-v0.3.8-linux-amd64-static.tar.gz /tmp/litestream.tar.gz
10+
RUN tar -C /usr/local/bin -xzf /tmp/litestream.tar.gz
911

10-
# Build the chiselled filesystem based on the desired slices.
11-
FROM ubuntu:$UBUNTU_RELEASE AS chiselled
12-
ARG UBUNTU_RELEASE
13-
ARG TARGETARCH
14-
15-
# Get chisel binary
16-
ADD https://github.com/canonical/chisel/releases/download/v0.9.1/chisel_v0.9.1_linux_$TARGETARCH.tar.gz chisel.tar.gz
17-
RUN tar -xvf chisel.tar.gz -C /usr/bin/
18-
RUN apt-get update \
19-
&& DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates
20-
21-
WORKDIR /rootfs
22-
23-
#RUN chisel cut --release ubuntu-$UBUNTU_RELEASE --root /rootfs \
12+
# RUN chisel cut --release ubuntu-$UBUNTU_RELEASE --root /rootfs \
2413
# base-files_base \
2514
# base-files_release-info \
2615
# ca-certificates_data \
@@ -36,6 +25,9 @@ RUN apt-get update \
3625
COPY ./ai_manager_service/migrations /var/lib/db/migrations
3726
EXPOSE 9000
3827
# COPY --from=chiselled /rootfs /
28+
COPY --from=builder /usr/local/bin/litestream /usr/local/bin/litestream
3929
COPY --from=builder /usr/src/app/target/release/monolith /usr/local/bin/twitch-alerts
4030
COPY ./frontend_api/assets /var/lib/assets/
41-
CMD ["/usr/local/bin/twitch-alerts"]
31+
COPY scripts/start.sh /scripts/start.sh
32+
COPY scripts/litestream.yaml /etc/litestream.yml
33+
CMD ["/scripts/start.sh"]

deployment/twitch-alerts-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ spec:
6262
# Start your application & Litestream to share a PVC data directory.
6363
containers:
6464
- name: twitch-alerts
65-
image: nullchannel/twitch-alerts:0.1.36
65+
image: nullchannel/twitch-alerts:0.1.37
6666
ports:
6767
- name: httpport
6868
containerPort: 8080

fly.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# fly.toml app configuration file generated for twitch-alerts on 2024-08-15T18:18:25-04:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'twitch-alerts'
7+
primary_region = 'atl'
8+
9+
[build]
10+
11+
[[services]]
12+
protocol = "tcp"
13+
internal_port = 9000
14+
auto_stop_machines = true
15+
auto_start_machines = true
16+
min_machines_running = 0
17+
18+
[[services.ports]]
19+
port = 9000
20+
handlers = ["tls", "http"]
21+
22+
[http_service]
23+
internal_port = 8080
24+
force_https = true
25+
auto_stop_machines = 'stop'
26+
auto_start_machines = true
27+
min_machines_running = 0
28+
processes = ['app']
29+
30+
[env]
31+
FRONTEND_ASSETS = "/var/lib/assets"
32+
HTTP_PORT = "8080"
33+
WEBSOCKET_HOST = "twitch-alerts.fly.dev"
34+
CHANNEL_ID = "99431252"
35+
RUST_ENV = "production"
36+
ENV = "production"
37+
AI_MIGRATIONS_DIR = "/var/lib/db"
38+
39+
[[vm]]
40+
size = 'shared-cpu-1x'

frontend_api/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<body>
1515
<main class="flex flex-row justify-center w-full">
16-
<div hx-ext="ws" ws-connect="ws://{{ hostname }}:{{ port }}/">
16+
<div hx-ext="ws" ws-connect="wss://{{ hostname }}:{{ port }}/">
1717
<div id="notifications"></div>
1818
</div>
1919
</main>

messages/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
use serde::{Deserialize, Serialize};
22

3+
#[derive(Serialize, Deserialize, Debug)]
4+
pub enum EventMessage {
5+
/// A new event message from Twitch.
6+
TwitchEvent(NewTwitchEventMessage),
7+
/// A new message to display.
8+
YoutubeEvent(YoutubeEventMessage),
9+
}
10+
11+
#[derive(Serialize, Deserialize, Debug)]
12+
pub struct YoutubeEventMessage {
13+
pub event: YoutubeEvent,
14+
pub message_id: String,
15+
pub message_at: String,
16+
}
17+
18+
#[derive(Serialize, Deserialize, Debug)]
19+
pub enum YoutubeEvent {
20+
Subscribe(String),
21+
}
22+
323
#[derive(Serialize, Deserialize, Debug)]
424
pub struct NewTwitchEventMessage {
525
pub event: TwitchEvent,

scripts/litestream.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dbs:
2+
- path: /data/db
3+
replicas:
4+
- url: s3://twitch-alerts.us-ord-1.linodeobjects.com/db

scripts/start.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Restore the database if it does not already exist.
5+
if [ -f /data/db ]; then
6+
echo "Database already exists, skipping restore"
7+
else
8+
echo "No database found, restoring from replica if exists"
9+
litestream restore -v -if-replica-exists -o /data/db s3://twitch-alerts.us-ord-1.linodeobjects.com/db
10+
fi
11+
12+
# Run litestream with your app as the subprocess.
13+
exec litestream replicate -exec "/usr/local/bin/twitch-alerts --db-path /data/db"

0 commit comments

Comments
 (0)