feat: implement OrchestratorCI workflow with environment setup and droplet creation script

This commit is contained in:
2025-09-22 18:09:12 +08:00
parent 92225317a7
commit 7fb9d24d3e
5 changed files with 141 additions and 5 deletions

View File

@@ -6,22 +6,35 @@ on:
spec:
required: true
type: string
outputs:
runner_id:
required: true
type: string
secrets:
DO_TOKEN:
required: true
outputs:
ready:
description: "The result of the orchestrator job"
value: ${{ jobs.provisioning.outputs.runner_id }} # Gunakan jobs
value: ${{ jobs.provisioning.outputs.ready }} # Gunakan jobs
jobs:
provisioning:
runs-on: gitea-orchestrator
name: OrchestratorCI Job
outputs:
runner_id: ${{ steps.provisioning.outputs.runner_id }} # Sesuaikan nama
ready: ${{ steps.provisioning.outputs.ready }} # Sesuaikan nama
steps:
- name: Run OrchestratorCI
id: provisioning
container: digitalocean/doctl
env:
SPEC: ${{ inputs.spec }}
RUNNER_ID: ${{ inputs.runner_id }}
DO_TOKEN: ${{ secrets.DO_TOKEN }}
run: |
echo "Running OrchestratorCI with spec: ${{ inputs.spec }}"
echo "Preparing Script..."
# Placeholder for actual OrchestratorCI commands
# Simulate a result output
echo "runner_id=pandeganteng" >> $GITHUB_OUTPUT
echo "ready=true" >> $GITHUB_OUTPUT

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.env

6
Dockerfile Normal file
View File

@@ -0,0 +1,6 @@
FROM alpine:latest
RUN apk --no-cache add curl bash git doctl
WORKDIR /app
CMD ["sleep", "3600"]

103
actions/orchestrating.sh Executable file
View File

@@ -0,0 +1,103 @@
#!/bin/bash
# Record start time
START_TIME=$(date +%s)
# Function to check list of required environment variables
check_env_vars() {
local missing_vars=()
for var in "$@"; do
if [ -z "${!var}" ]; then
missing_vars+=("$var")
fi
done
if [ ${#missing_vars[@]} -ne 0 ]; then
echo "Error: The following environment variables are not set: ${missing_vars[*]}"
exit 1
fi
}
# Function to check if doctl is available
check_doctl() {
if ! command -v doctl &> /dev/null; then
echo "Error: doctl is not installed or not in PATH"
echo "Please install doctl: https://docs.digitalocean.com/reference/doctl/how-to/install/"
exit 1
fi
}
# Function to setup SSH private key
setup_ssh_key() {
if [ -z "$SSH_PRIVATE_KEY" ]; then
echo "Error: SSH_PRIVATE_KEY environment variable is not set"
exit 1
fi
# Create SSH directory if it doesn't exist
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Write private key to file (decode if base64)
if echo "$SSH_PRIVATE_KEY" | base64 -d > /dev/null 2>&1; then
echo "$SSH_PRIVATE_KEY" | base64 -d > ~/.ssh/id_rsa
else
echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
fi
chmod 600 ~/.ssh/id_rsa
echo "SSH private key has been set up successfully"
}
# Function to create droplet
create_droplet() {
local name="${1:-runner-${RUNNER_ID}}"
local size="${2:-s-1vcpu-1gb}"
local image="${3:-ubuntu-22-04-x64}"
local region="${4:-sgp1}"
echo "Creating droplet: $name"
echo "Size: $size, Image: $image, Region: $region"
# Authenticate doctl
doctl auth init --access-token "$DO_TOKEN"
# Create droplet
local droplet_id=$(doctl compute droplet create "$name" \
--size "$size" \
--image "$image" \
--region "$region" \
--ssh-keys $(doctl compute ssh-key list --format ID --no-header | tr '\n' ',' | sed 's/,$//' || echo "") \
--format ID \
--no-header \
--wait)
if [ -n "$droplet_id" ]; then
echo "Droplet created successfully with ID: $droplet_id"
echo "Droplet name: $name"
# Get droplet IP
local droplet_ip=$(doctl compute droplet get "$droplet_id" --format PublicIPv4 --no-header)
echo "Droplet IP: $droplet_ip"
return 0
else
echo "Error: Failed to create droplet"
return 1
fi
}
# Check required environment variables
check_env_vars "SPEC" "RUNNER_ID" "DO_TOKEN" "SSH_PRIVATE_KEY"
# Check if doctl is available
check_doctl
# Setup SSH private key
setup_ssh_key
create_droplet
# Calculate and display execution time
END_TIME=$(date +%s)
EXECUTION_TIME=$((END_TIME - START_TIME))
echo "Script execution time: ${EXECUTION_TIME} seconds"

13
docker-compose.yml Normal file
View File

@@ -0,0 +1,13 @@
services:
app:
build:
context: .
dockerfile: Dockerfile
entrypoint: ""
command: ["sleep", "3600"]
environment:
- DO_TOKEN=dop_v1_edf8bb32e734cf0dbbb40ce9d2b7ad494277caced8636a4823aede610b6c31fa
- RUNNER_ID=pandeganteng
- SPEC=default
volumes:
- ./actions:/actions