fix: update Dockerfile to use Alpine base image and add cleanup script for droplet management
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
FROM catthehacker/ubuntu:runner-22.04
|
||||
USER root
|
||||
RUN apt-get update && apt-get install -y curl bash git wget openssh-client
|
||||
|
||||
RUN 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 \
|
||||
&& rm doctl-1.141.0-linux-amd64.tar.gz
|
||||
FROM alpine:latest
|
||||
RUN apk add --no-cache curl bash git doctl openssh
|
||||
|
||||
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
|
||||
|
||||
RUN mkdir -p /var/run/act/
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user