Skip to content

Commit f328856

Browse files
committed
chore(deploy): streamline Fly.io pipeline and harden container build
Signed-off-by: JmPotato <github@ipotato.me>
1 parent e005a4d commit f328856

File tree

4 files changed

+53
-37
lines changed

4 files changed

+53
-37
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
target/
2+
.git/
3+
.github/
4+
.gitignore
5+
*.md

.github/workflows/fly-deploy.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
22

3-
name: Fly.io Demo Deploy
3+
name: Deploy to Fly.io
44
on:
55
push:
66
branches:
77
- main
8+
9+
concurrency:
10+
group: deploy
11+
cancel-in-progress: true
12+
813
jobs:
914
deploy:
1015
name: Deploy app
1116
runs-on: ubuntu-latest
12-
concurrency: deploy-group # optional: ensure only one action runs at a time
1317
steps:
14-
- uses: actions/checkout@v4
15-
- uses: superfly/flyctl-actions/setup-flyctl@master
16-
- env:
18+
- uses: actions/checkout@v6
19+
- name: Install fly
20+
run: |
21+
curl -L https://fly.io/install.sh | sh
22+
echo "$HOME/.fly/bin" >> "$GITHUB_PATH"
23+
- name: Set secrets
24+
run: fly secrets set --stage MYSQL_CONNECTION_URL="${MYSQL_CONNECTION_URL}" UMAMI_ID="${UMAMI_ID}"
25+
env:
1726
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
1827
MYSQL_CONNECTION_URL: ${{ secrets.MYSQL_CONNECTION_URL }}
1928
UMAMI_ID: ${{ secrets.UMAMI_ID }}
20-
run: |
21-
flyctl secrets set --stage MYSQL_CONNECTION_URL=${MYSQL_CONNECTION_URL} UMAMI_ID=${UMAMI_ID}
22-
flyctl deploy --remote-only
29+
- name: Deploy
30+
run: fly deploy --remote-only
31+
env:
32+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

Dockerfile

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,35 @@
11
# syntax=docker/dockerfile:1
22

3-
################################################################################
4-
# Create a stage for building the application.
5-
6-
ARG RUST_VERSION=latest
3+
ARG RUST_VERSION=1.84
74
ARG APP_NAME=rsomhap
85

6+
################################################################################
7+
# Build stage
8+
99
FROM rust:${RUST_VERSION} AS builder
1010
ARG APP_NAME
11-
1211
WORKDIR /usr/src/app
1312

14-
# Build the application.
15-
# Leverage a cache mount to /usr/local/cargo/registry/
16-
# for downloaded dependencies and a cache mount to /app/target/ for
17-
# compiled dependencies which will speed up subsequent builds.
18-
# Once built, copy the executable to an output directory before
19-
# the cache mounted /app/target is unmounted.
20-
COPY Cargo.toml ./
13+
COPY Cargo.toml Cargo.lock ./
2114
COPY src ./src
15+
2216
RUN --mount=type=cache,target=/usr/src/app/target \
2317
--mount=type=cache,target=/usr/local/cargo/registry \
24-
cargo build --release --bin ${APP_NAME} && cp ./target/release/${APP_NAME} ./${APP_NAME}
18+
cargo build --release --locked --bin ${APP_NAME} \
19+
&& cp ./target/release/${APP_NAME} ./${APP_NAME}
2520

2621
################################################################################
27-
# Create a new stage for running the application that contains the minimal
28-
# runtime dependencies for the application. This often uses a different base
29-
# image from the build stage where the necessary files are copied from the build
30-
# stage.
22+
# Runtime stage
3123

3224
FROM debian:bookworm-slim AS final
3325
ARG APP_NAME
3426

27+
RUN apt-get update \
28+
&& apt-get install -y --no-install-recommends ca-certificates curl \
29+
&& rm -rf /var/lib/apt/lists/*
30+
3531
WORKDIR /usr/src/app
3632

37-
# Create a non-privileged user that the app will run under.
38-
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
3933
ARG UID=10001
4034
RUN adduser \
4135
--disabled-password \
@@ -45,18 +39,17 @@ RUN adduser \
4539
--no-create-home \
4640
--uid "${UID}" \
4741
appuser
48-
USER appuser
4942

50-
# Copy the executable from the "build" stage.
51-
COPY --from=builder /usr/src/app/${APP_NAME} .
43+
# Copy the executable from the build stage.
44+
COPY --from=builder --chown=appuser:appuser /usr/src/app/${APP_NAME} .
5245

5346
# Copy the necessary files.
54-
COPY templates ./templates
55-
COPY static ./static
56-
COPY config.toml ./
47+
COPY --chown=appuser:appuser templates ./templates
48+
COPY --chown=appuser:appuser static ./static
49+
COPY --chown=appuser:appuser config.toml ./
50+
51+
USER appuser
5752

58-
# Expose the port that the application listens on.
5953
EXPOSE 5299
6054

61-
# What the container should run when it is started.
6255
CMD ["./rsomhap"]

docker-compose.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
version: "3"
2-
31
services:
42
rsomhap:
53
build: .
64
image: rsomhap:latest
75
container_name: rsomhap
6+
restart: unless-stopped
87
ports:
98
- "5299:5299"
9+
environment:
10+
- MYSQL_CONNECTION_URL
11+
- UMAMI_ID
12+
healthcheck:
13+
test: ["CMD-SHELL", "curl -sf http://localhost:5299/ping || exit 1"]
14+
interval: 30s
15+
timeout: 3s
16+
retries: 3
17+
start_period: 5s

0 commit comments

Comments
 (0)