Compare commits
11 Commits
fa4f5b63ff
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 0e4659ebd8 | |||
| 008a5d92a7 | |||
| 29a90ef7bc | |||
| 85b1735213 | |||
| e8cf46f8d9 | |||
| 58f535abcf | |||
| 58f69f073a | |||
| f2b16b21e1 | |||
| 3f44a10c0f | |||
| e836cbfa02 | |||
| 31827c8d99 |
30
.github/workflows/orchestratorci-cleanup.yml
vendored
30
.github/workflows/orchestratorci-cleanup.yml
vendored
@@ -3,14 +3,36 @@ name: OrchestratorCI
|
|||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
runner_id:
|
droplet_id:
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
DO_TOKEN:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
done:
|
||||||
|
description: "The result of the orchestrator job"
|
||||||
|
value: ${{ jobs.cleanup.outputs.done }} # Gunakan jobs
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
provisioning:
|
cleanup:
|
||||||
runs-on: gitea-orchestrator
|
runs-on: gitea-orchestrator
|
||||||
name: OrchestratorCI Cleanup Job
|
name: OrchestratorCI Cleanup Job
|
||||||
|
outputs:
|
||||||
|
done: ${{ steps.cleanup.outputs.done }} # Sesuaikan nama
|
||||||
steps:
|
steps:
|
||||||
- name: Run OrchestratorCI
|
- name: Run Cleanup OrchestratorCI
|
||||||
|
id: cleanup
|
||||||
|
env:
|
||||||
|
DROPLET_ID: ${{ inputs.droplet_id }}
|
||||||
|
DO_TOKEN: ${{ secrets.DO_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
echo "Cleanup Sucess for runner_id: ${{ inputs.runner_id }}"
|
wget https://github.com/digitalocean/doctl/releases/download/v1.141.0/doctl-1.141.0-linux-amd64.tar.gz
|
||||||
|
tar -xvf doctl-1.141.0-linux-amd64.tar.gz
|
||||||
|
mv doctl /usr/local/bin
|
||||||
|
|
||||||
|
curl https://git.btwazure.com/btwedutech/workflows/raw/branch/main/orchestrator/cleanup.sh -o cleanup.sh
|
||||||
|
chmod +x cleanup.sh
|
||||||
|
./cleanup.sh
|
||||||
24
.github/workflows/orchestratorci.yml
vendored
24
.github/workflows/orchestratorci.yml
vendored
@@ -3,13 +3,17 @@ name: OrchestratorCI
|
|||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
spec:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
runner_id:
|
runner_id:
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
spec:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: "s-1vcpu-1gb"
|
||||||
|
image:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: "200895606" # Ubuntu 22.04 x64
|
||||||
secrets:
|
secrets:
|
||||||
DO_TOKEN:
|
DO_TOKEN:
|
||||||
required: true
|
required: true
|
||||||
@@ -33,14 +37,22 @@ jobs:
|
|||||||
name: OrchestratorCI Job
|
name: OrchestratorCI Job
|
||||||
outputs:
|
outputs:
|
||||||
ready: ${{ steps.provisioning.outputs.ready }} # Sesuaikan nama
|
ready: ${{ steps.provisioning.outputs.ready }} # Sesuaikan nama
|
||||||
|
droplet_id: ${{ steps.provisioning.outputs.droplet_id }}
|
||||||
|
droplet_ip: ${{ steps.provisioning.outputs.droplet_ip }}
|
||||||
steps:
|
steps:
|
||||||
- name: Run OrchestratorCI
|
- name: Run OrchestratorCI
|
||||||
id: provisioning
|
id: provisioning
|
||||||
container: registry.btwazure.com/orchestrator/app:latest
|
|
||||||
env:
|
env:
|
||||||
SPEC: ${{ inputs.spec }}
|
SPEC: ${{ inputs.spec }}
|
||||||
|
IMAGE: ${{ inputs.image }}
|
||||||
RUNNER_ID: ${{ inputs.runner_id }}
|
RUNNER_ID: ${{ inputs.runner_id }}
|
||||||
DO_TOKEN: ${{ secrets.DO_TOKEN }}
|
DO_TOKEN: ${{ secrets.DO_TOKEN }}
|
||||||
SSH_PRIVATE_KEY_DECODED: ${{ secrets.SSH_PRIVATE_KEY_DECODED }}
|
SSH_PRIVATE_KEY_DECODED: ${{ secrets.SSH_PRIVATE_KEY_DECODED }}
|
||||||
run: |
|
run: |
|
||||||
orchestrating.sh
|
wget https://github.com/digitalocean/doctl/releases/download/v1.141.0/doctl-1.141.0-linux-amd64.tar.gz
|
||||||
|
tar -xvf doctl-1.141.0-linux-amd64.tar.gz
|
||||||
|
mv doctl /usr/local/bin
|
||||||
|
|
||||||
|
curl https://git.btwazure.com/btwedutech/workflows/raw/branch/main/orchestrator/orchestrating.sh -o orchestrating.sh
|
||||||
|
chmod +x orchestrating.sh
|
||||||
|
./orchestrating.sh
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
RUN apk --no-cache add curl bash git doctl openssh
|
RUN apk add --no-cache curl bash git doctl openssh
|
||||||
|
|
||||||
WORKDIR /root
|
COPY orchestrating.sh /usr/local/bin/orchestrating
|
||||||
|
COPY cleanup.sh /usr/local/bin/cleanup
|
||||||
|
RUN chmod 755 /usr/local/bin/orchestrating /usr/local/bin/cleanup
|
||||||
|
|
||||||
COPY orchestrating.sh /usr/local/bin/orchestrating.sh
|
RUN mkdir -p /var/run/act/
|
||||||
COPY cleanup.sh /usr/local/bin/cleanup.sh
|
|
||||||
RUN chmod 755 /usr/local/bin/orchestrating.sh /usr/local/bin/cleanup.sh
|
|
||||||
|
|
||||||
CMD ["tail" ,"-f" ,"/dev/null"]
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 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 destroy droplet using environment variable
|
||||||
|
cleanup_droplet() {
|
||||||
|
# Get droplet ID from environment variable
|
||||||
|
local droplet_id="$DROPLET_ID"
|
||||||
|
|
||||||
|
echo "Destroying droplet with ID: $droplet_id"
|
||||||
|
|
||||||
|
# Authenticate doctl
|
||||||
|
doctl auth init --access-token "$DO_TOKEN"
|
||||||
|
|
||||||
|
# Destroy droplet
|
||||||
|
if doctl compute droplet delete "$droplet_id" --force; then
|
||||||
|
echo "Droplet $droplet_id destroyed successfully"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "Error: Failed to destroy droplet $droplet_id"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check required environment variables
|
||||||
|
check_env_vars "DROPLET_ID" "DO_TOKEN"
|
||||||
|
|
||||||
|
# Check if doctl is available
|
||||||
|
check_doctl
|
||||||
|
|
||||||
|
# Execute cleanup
|
||||||
|
cleanup_droplet
|
||||||
@@ -92,7 +92,7 @@ destroy_droplet() {
|
|||||||
create_droplet() {
|
create_droplet() {
|
||||||
local name="${1:-runner-${RUNNER_ID}}"
|
local name="${1:-runner-${RUNNER_ID}}"
|
||||||
local size="${2:-s-1vcpu-1gb}"
|
local size="${2:-s-1vcpu-1gb}"
|
||||||
local image="${3:-200811356}"
|
local image="${3:-200895606}"
|
||||||
local region="${4:-sgp1}"
|
local region="${4:-sgp1}"
|
||||||
|
|
||||||
echo "Creating droplet: $name"
|
echo "Creating droplet: $name"
|
||||||
@@ -154,7 +154,7 @@ test_ssh_connection() {
|
|||||||
local droplet_ip="$1"
|
local droplet_ip="$1"
|
||||||
local max_attempts=10
|
local max_attempts=10
|
||||||
local attempt=1
|
local attempt=1
|
||||||
local wait_time=30
|
local wait_time=10
|
||||||
|
|
||||||
echo "Testing SSH connection to $droplet_ip..."
|
echo "Testing SSH connection to $droplet_ip..."
|
||||||
|
|
||||||
@@ -250,7 +250,7 @@ setup_vm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Check required environment variables
|
# Check required environment variables
|
||||||
check_env_vars "SPEC" "RUNNER_ID" "DO_TOKEN" "SSH_PRIVATE_KEY_DECODED"
|
check_env_vars "SPEC" "IMAGE" "RUNNER_ID" "DO_TOKEN" "SSH_PRIVATE_KEY_DECODED"
|
||||||
|
|
||||||
# Check if doctl is available
|
# Check if doctl is available
|
||||||
check_doctl
|
check_doctl
|
||||||
@@ -258,7 +258,7 @@ check_doctl
|
|||||||
# Setup SSH private key
|
# Setup SSH private key
|
||||||
setup_ssh_key
|
setup_ssh_key
|
||||||
|
|
||||||
create_droplet
|
create_droplet "$RUNNER_ID" "$SPEC" "$IMAGE"
|
||||||
|
|
||||||
# Calculate and display execution time
|
# Calculate and display execution time
|
||||||
END_TIME=$(date +%s)
|
END_TIME=$(date +%s)
|
||||||
|
|||||||
Reference in New Issue
Block a user