Skip to content

Commit 6f39134

Browse files
committed
feat(backend): modernize Dockerfile and implement manual deployment script
1 parent 837c735 commit 6f39134

3 files changed

Lines changed: 58 additions & 65 deletions

File tree

apps/backend/Dockerfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
FROM rust:latest AS builder
1+
FROM rust:1-bookworm AS builder
22

3-
RUN apt-get update && apt-get install -y musl-tools
4-
RUN rustup target add x86_64-unknown-linux-musl
3+
# Install system dependencies if needed (e.g. openssl, although it seems we don't need it yet)
4+
# RUN apt-get update && apt-get install -y pkg-config libssl-dev
55

66
WORKDIR /app
77
COPY . .
88

9-
# Build with MUSL for a static binary
10-
RUN cargo build --release --target x86_64-unknown-linux-musl --manifest-path apps/backend/Cargo.toml
9+
# Build for the native architecture or specified platform
10+
RUN cargo build --release --manifest-path apps/backend/Cargo.toml && \
11+
mkdir -p /app/bin && \
12+
find /app -name verifyos-backend -type f -executable -exec cp {} /app/bin/verifyos-backend \;
1113

12-
FROM alpine:latest
13-
RUN apk add --no-cache ca-certificates
14+
FROM debian:bookworm-slim
15+
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
1416

15-
COPY --from=builder /app/apps/backend/target/x86_64-unknown-linux-musl/release/verifyos-backend /usr/local/bin/verifyos-backend
17+
# Copy the binary from the staging bin folder
18+
COPY --from=builder /app/bin/verifyos-backend /usr/local/bin/verifyos-backend
1619

1720
ENV RUST_LOG=info
1821
EXPOSE 7070

apps/backend/deploy.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
# verifyOS Backend Manual Deployment Script
4+
# This script builds the Docker image and pushes it to Amazon ECR.
5+
6+
set -e
7+
8+
# Configuration
9+
REGION="ap-southeast-1"
10+
REPO_NAME="verifyos-backend"
11+
SERVICE_NAME="verifyos-backend"
12+
13+
echo "🚀 Starting manual deployment for $SERVICE_NAME..."
14+
15+
# 1. Login to ECR
16+
echo "🔑 Logging in to Amazon ECR..."
17+
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
18+
ECR_URL="$AWS_ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com"
19+
aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $ECR_URL
20+
21+
# 2. Build Docker Image
22+
echo "📦 Building Docker image for linux/amd64..."
23+
# Run build from project root to include core library
24+
cd ../..
25+
docker build --platform linux/amd64 -t $REPO_NAME -f apps/backend/Dockerfile .
26+
docker tag $REPO_NAME:latest $ECR_URL/$REPO_NAME:latest
27+
28+
# 3. Push to ECR
29+
echo "📤 Pushing image to ECR..."
30+
docker push $ECR_URL/$REPO_NAME:latest
31+
32+
# 4. Deploy to App Runner
33+
echo "🔄 Updating App Runner service..."
34+
# Find the Service ARN
35+
SERVICE_ARN=$(aws apprunner list-services --region $REGION --query "ServiceSummaryList[?ServiceName=='$SERVICE_NAME'].ServiceArn" --output text)
36+
37+
if [ -z "$SERVICE_ARN" ] || [ "$SERVICE_ARN" == "None" ]; then
38+
echo "❌ Error: Could not find App Runner service named $SERVICE_NAME in $REGION"
39+
exit 1
40+
fi
41+
42+
echo "📍 Found Service ARN: $SERVICE_ARN"
43+
aws apprunner start-deployment --region $REGION --service-arn "$SERVICE_ARN"
44+
45+
echo "✅ Deployment initiated! Check AWS Console for progress."

apps/backend/src/app/scan.rs

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,8 @@ impl ScanService {
6969

7070
let run_started = Instant::now();
7171
let bundle_path = bundle_path.as_ref();
72-
let run = match engine.run(bundle_path) {
73-
Ok(run) => run,
74-
Err(OrchestratorError::AppBundleNotFound)
75-
if is_zip_like(bundle_path) =>
76-
{
77-
match extract_app_bundle(bundle_path) {
78-
Ok((dir, app_path)) => {
79-
let run = engine
80-
.run_on_bundle(&app_path, run_started)
81-
.map_err(|err| ScanError::ScanFailed(err.to_string()))?;
82-
std::mem::drop(dir);
83-
run
84-
}
85-
Err(err) => {
86-
return Err(ScanError::ScanFailed(format!(
87-
"{}. If you only have a .app, zip it and upload the .zip",
88-
err
89-
)));
90-
}
91-
}
92-
}
93-
Err(err) => return Err(ScanError::ScanFailed(err.to_string())),
94-
};
72+
let run = engine.run(bundle_path)
73+
.map_err(|err| ScanError::ScanFailed(err.to_string()))?;
9574

9675
let mut report = build_report(run.results, run.total_duration_ms, run.cache_stats);
9776
let baseline = request.baseline.as_ref().map(|baseline| apply_baseline(&mut report, baseline));
@@ -137,41 +116,7 @@ fn build_rule_selection(
137116
})
138117
}
139118

140-
fn is_zip_like(path: &Path) -> bool {
141-
path.extension()
142-
.and_then(|ext| ext.to_str())
143-
.is_some_and(|ext| ext.eq_ignore_ascii_case("zip") || ext.eq_ignore_ascii_case("ipa"))
144-
}
145119

146-
fn extract_app_bundle(path: &Path) -> Result<(tempfile::TempDir, PathBuf), String> {
147-
let file = std::fs::File::open(path).map_err(|err| err.to_string())?;
148-
let mut archive = ZipArchive::new(file).map_err(|err| err.to_string())?;
149-
let dir = tempfile::tempdir().map_err(|err| err.to_string())?;
150-
archive
151-
.extract(dir.path())
152-
.map_err(|err| err.to_string())?;
153-
154-
let app_path = find_app_bundle(dir.path())
155-
.ok_or_else(|| "Could not locate .app in uploaded archive".to_string())?;
156-
Ok((dir, app_path))
157-
}
158-
159-
fn find_app_bundle(root: &Path) -> Option<PathBuf> {
160-
let mut queue = vec![root.to_path_buf()];
161-
while let Some(dir) = queue.pop() {
162-
let entries = std::fs::read_dir(&dir).ok()?;
163-
for entry in entries.flatten() {
164-
let path = entry.path();
165-
if path.is_dir() {
166-
if path.extension().is_some_and(|ext| ext == "app") {
167-
return Some(path);
168-
}
169-
queue.push(path);
170-
}
171-
}
172-
}
173-
None
174-
}
175120

176121
fn load_xcode_project(
177122
path: &Path,

0 commit comments

Comments
 (0)