Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build-test-push-synvya.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
host: ${{ secrets.EC2_STAGING_HOST }}
username: ec2-user
key: ${{ secrets.EC2_STAGING_SSH_KEY }}
command_timeout: 30m
command_timeout: 60m
script: |
set -euo pipefail
cd /opt/synvya/keycast
Expand Down Expand Up @@ -180,7 +180,7 @@ jobs:
host: ${{ secrets.EC2_PRODUCTION_HOST }}
username: ec2-user
key: ${{ secrets.EC2_PRODUCTION_SSH_KEY }}
command_timeout: 30m
command_timeout: 60m
script: |
set -euo pipefail
cd /opt/synvya/keycast
Expand Down Expand Up @@ -226,7 +226,7 @@ jobs:
host: ${{ secrets.EC2_STAGING_HOST }}
username: ec2-user
key: ${{ secrets.EC2_STAGING_SSH_KEY }}
command_timeout: 30m
command_timeout: 60m
script: |
set -e

Expand Down Expand Up @@ -307,7 +307,7 @@ jobs:
host: ${{ secrets.EC2_PRODUCTION_HOST }}
username: ec2-user
key: ${{ secrets.EC2_PRODUCTION_SSH_KEY }}
command_timeout: 30m
command_timeout: 60m
script: |
set -e

Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
# Build stage for Bun frontend
FROM oven/bun:1 AS web-builder

# Force serial execution: only start web-builder after rust-builder
# completes. BuildKit otherwise runs the two stages in parallel, which
# pushes a small EC2 (e.g. t3.medium) into swap thrash and locks the
# host. This COPY creates a build-graph dependency on rust-builder.
COPY --from=rust-builder /artifacts/keycast /tmp/.rust-builder-done

# Install build essentials for native modules
RUN apt-get update && apt-get install -y \
python3 \
Expand Down
22 changes: 19 additions & 3 deletions scripts/ec2-prepare-host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ SWAPFILE="${SWAPFILE:-/swapfile}"
SWAP_SIZE="${SWAP_SIZE:-4G}"
CARGO_JOBS="${CARGO_JOBS:-2}"

# When invoked under sudo, $HOME points to /root. We want the cargo
# config to land in the invoking user's home so the workflow (which
# runs as ec2-user over SSH) reads the same file.
if [ -n "${SUDO_USER:-}" ] && [ "${SUDO_USER}" != "root" ]; then
TARGET_HOME="$(getent passwd "${SUDO_USER}" | cut -d: -f6)"
TARGET_USER="${SUDO_USER}"
else
TARGET_HOME="${HOME}"
TARGET_USER="$(id -un)"
fi

echo "=== ec2-prepare-host: ensure swap (${SWAP_SIZE} at ${SWAPFILE}) ==="
if swapon --show=NAME --noheadings | grep -qx "${SWAPFILE}"; then
echo "swap already active at ${SWAPFILE}"
Expand All @@ -25,16 +36,21 @@ else
echo "swap enabled at ${SWAPFILE}"
fi

echo "=== ec2-prepare-host: ensure ~/.cargo/config.toml jobs=${CARGO_JOBS} ==="
mkdir -p "${HOME}/.cargo"
CARGO_CFG="${HOME}/.cargo/config.toml"
echo "=== ec2-prepare-host: ensure ${TARGET_HOME}/.cargo/config.toml jobs=${CARGO_JOBS} ==="
mkdir -p "${TARGET_HOME}/.cargo"
CARGO_CFG="${TARGET_HOME}/.cargo/config.toml"
if [ ! -f "${CARGO_CFG}" ] || ! grep -qE '^\[build\]' "${CARGO_CFG}"; then
cat >> "${CARGO_CFG}" <<EOF

[build]
jobs = ${CARGO_JOBS}
EOF
echo "wrote [build] jobs=${CARGO_JOBS} to ${CARGO_CFG}"
# If we're running under sudo, restore ownership so the invoking
# user (and cargo running as that user) can read/write the config.
if [ "${TARGET_USER}" != "$(id -un)" ]; then
chown -R "${TARGET_USER}:${TARGET_USER}" "${TARGET_HOME}/.cargo"
fi
else
echo "${CARGO_CFG} already has [build] section, leaving as-is"
fi
Expand Down
Loading