-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor runner for rust condition (#15)
* chore(feat): impl case for rust without test * chore(feat): add prod base image build
- Loading branch information
Showing
5 changed files
with
129 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Build Base Images | ||
|
||
on: | ||
workflow_dispatch: # Manual trigger | ||
push: | ||
paths: | ||
- "baseImages/**" | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-base-images: | ||
name: Build Base Images on Droplet | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
image: | ||
- { name: "rust", tag: "rs-base", path: "baseImages/rust" } | ||
- { | ||
name: "typescript", | ||
tag: "ts-base", | ||
path: "baseImages/typescript", | ||
} | ||
- { name: "python", tag: "py-base", path: "baseImages/python" } | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure SSH | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "${{ secrets.PROD_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | ||
chmod 600 ~/.ssh/id_rsa | ||
ssh-keyscan -H ${{ secrets.PROD_DROPLET_IP }} >> ~/.ssh/known_hosts | ||
# Create directory and copy Dockerfile | ||
- name: Copy Dockerfile to Droplet | ||
run: | | ||
ssh ${{ secrets.PROD_DROPLET_USER }}@${{ secrets.PROD_DROPLET_IP }} "mkdir -p ~/base-images/${{ matrix.image.name }}" | ||
scp ${{ matrix.image.path }}/Dockerfile ${{ secrets.PROD_DROPLET_USER }}@${{ secrets.PROD_DROPLET_IP }}:~/base-images/${{ matrix.image.name }}/Dockerfile | ||
# Build the image on the droplet | ||
- name: Build Base Image | ||
run: | | ||
ssh ${{ secrets.PROD_DROPLET_USER }}@${{ secrets.PROD_DROPLET_IP }} << 'EOF' | ||
cd ~/base-images/${{ matrix.image.name }} | ||
docker build -t ${{ matrix.image.tag }}:latest . | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { TestRepoManager } from "./testRepoManager"; | ||
import path from "path"; | ||
import fs from "fs/promises"; | ||
|
||
export async function generateRunScript( | ||
repoDir: string, | ||
language: string, | ||
currentStep: number, | ||
testContent: string | null, | ||
): Promise<void> { | ||
const runScript = `#!/bin/bash | ||
set -e # Exit on any error | ||
if [ -f "requirements.txt" ]; then | ||
# For Python projects | ||
${ | ||
testContent | ||
? `pytest ./app/stage${currentStep}${TestRepoManager.getTestExtension(language)} -v` | ||
: "python ./app/main.py" | ||
} | ||
elif [ -f "Cargo.toml" ]; then | ||
# For Rust projects | ||
cargo build ${testContent ? "--quiet" : ""} | ||
${ | ||
testContent ? `cargo test --test stage${currentStep}_test` : "cargo run" | ||
} | ||
else | ||
# For TypeScript projects | ||
${ | ||
testContent | ||
? `bun test ./app/stage${currentStep}${TestRepoManager.getTestExtension(language)}` | ||
: "bun run start" | ||
} | ||
fi | ||
`; | ||
|
||
const runScriptPath = path.join(repoDir, ".hxckr", "run.sh"); | ||
await fs.writeFile(runScriptPath, runScript); | ||
await fs.chmod(runScriptPath, 0o755); // Making it executable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters