-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bac35d3
commit ffbafcf
Showing
7 changed files
with
251 additions
and
1 deletion.
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
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,28 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# Source the shared library | ||
. "$(dirname "$0")/../lib/validate.sh" | ||
|
||
check_var TARGET_DIR | ||
check_var DOCKERFILE_PATH | ||
check_var IMAGE_NAME | ||
check_var REGISTRY_URL | ||
|
||
# Create a temporary build directory | ||
BUILD_DIR=$(mktemp -d) | ||
trap 'rm -rf "$BUILD_DIR"' EXIT | ||
|
||
# Copy the target directory contents to the build directory | ||
cp -r "$TARGET_DIR"/* "$BUILD_DIR" | ||
|
||
# Change to the build directory | ||
cd "$BUILD_DIR" | ||
docker build -f "$DOCKERFILE_PATH" -t "$IMAGE_NAME" . | ||
|
||
# Tag the image with the registry URL | ||
docker tag "$IMAGE_NAME" "${REGISTRY_URL}/${IMAGE_NAME}" | ||
|
||
# Push the image to the registry | ||
docker push "${REGISTRY_URL}/${IMAGE_NAME}" |
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,38 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# Source the shared library | ||
. "$(dirname "$0")/../lib/validate.sh" | ||
|
||
check_var GIT_REPO_URL | ||
check_var GIT_REF | ||
check_var TARGET_DIR | ||
|
||
# Create a lock file in /tmp (using TARGET_DIR in name to make it unique) | ||
LOCK_FILE="/tmp/$(echo "${TARGET_DIR}" | sed 's/\//_/g').lock" | ||
touch "$LOCK_FILE" | ||
|
||
# Attempt to acquire lock, fail if cannot obtain it | ||
echo "Acquiring lock..." | ||
( | ||
if ! flock -n 9; then | ||
echo "Error: Another process is currently updating the repository" | ||
exit 1 | ||
fi | ||
|
||
echo "Syncing with remote repository" | ||
|
||
if [ -d "$TARGET_DIR/.git" ]; then | ||
echo "Repository already exists, updating origin and pulling latest changes" | ||
cd "$TARGET_DIR" | ||
# Update the remote origin URL if it has changed | ||
git remote set-url origin "$GIT_REPO_URL" | ||
git fetch origin | ||
git checkout "$GIT_REF" | ||
git pull origin "$GIT_REF" | ||
else | ||
echo "Cloning repository" | ||
git clone --depth 1 "$GIT_REPO_URL" -b "$GIT_REF" "$TARGET_DIR" | ||
fi | ||
) 9>"$LOCK_FILE" |
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,67 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# Source the shared library | ||
. "$(dirname "$0")/../lib/validate.sh" | ||
|
||
echo "Starting s3 download script validation" | ||
|
||
check_var SRC_FILE_PATH | ||
check_var DEST_FILE_PATH | ||
check_var S3_ACCESS_KEY | ||
check_var S3_SECRET_KEY | ||
check_var S3_ENDPOINT | ||
check_var S3_REGION | ||
check_var S3_BUCKET | ||
check_var PATH_PREFIX | ||
|
||
DEST_FILE_PATH="/$DEST_FILE_PATH" | ||
|
||
echo "Removing $DEST_FILE_PATH/*" | ||
rm -rf "$DEST_FILE_PATH/*" 2> /dev/null || true | ||
|
||
echo "Downloading from s3://$S3_BUCKET/$PATH_PREFIX/$SRC_FILE_PATH" | ||
|
||
case "$SRC_FILE_PATH" in | ||
*".tar.gz") | ||
ARCHIVE_FORMAT="tar.gz" | ||
;; | ||
*".zip") | ||
ARCHIVE_FORMAT="zip" | ||
;; | ||
*) | ||
echo "Unsupported archive format: $SRC_FILE_PATH" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
ARCHIVE_PATH="/tmp/archive.$ARCHIVE_FORMAT" | ||
|
||
s3cmd --access_key "$S3_ACCESS_KEY" \ | ||
--secret_key "$S3_SECRET_KEY" \ | ||
--host "$S3_ENDPOINT" \ | ||
--host-bucket "$S3_ENDPOINT" \ | ||
--region "$S3_REGION" \ | ||
get "s3://$S3_BUCKET/$PATH_PREFIX/$SRC_FILE_PATH" "$ARCHIVE_PATH" | ||
|
||
echo "Extracting $SRC_FILE_PATH to $DEST_FILE_PATH" | ||
|
||
case "$ARCHIVE_FORMAT" in | ||
"tar.gz") | ||
tar -xzvf "$ARCHIVE_PATH" -C "$DEST_FILE_PATH" | ||
;; | ||
"zip") | ||
apk add zip | ||
unzip "$ARCHIVE_PATH" | ||
;; | ||
*) | ||
echo "Unsupported archive format: $ARCHIVE_FORMAT" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
echo "Removing $ARCHIVE_PATH" | ||
rm -f "$ARCHIVE_PATH" | ||
|
||
echo "Done" |
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,34 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# Source the shared library | ||
. "$(dirname "$0")/../lib/validate.sh" | ||
|
||
echo "Starting s3 test upload validation" | ||
|
||
# Create temporary test file | ||
TEST_FILE="/tmp/check-access.txt" | ||
|
||
# Generate content for the test file | ||
{ | ||
echo "https://ptah.sh" | ||
echo "Test upload date: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" | ||
echo "S3 Endpoint: $S3_ENDPOINT" | ||
echo "S3 Region: $S3_REGION" | ||
echo "S3 Bucket: $S3_BUCKET" | ||
echo "Path Prefix: $PATH_PREFIX" | ||
} > "$TEST_FILE" | ||
|
||
echo "Created test file with the following content:" | ||
cat "$TEST_FILE" | ||
|
||
# Set up environment variables for s3_upload.sh | ||
export ARCHIVE_FORMAT="" | ||
export SRC_FILE_PATH="$TEST_FILE" | ||
export DEST_FILE_PATH="check-access.txt" | ||
|
||
# Call the main upload script | ||
"$(dirname "$0")/s3_upload.sh" | ||
|
||
echo "Test upload completed successfully" |
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,66 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# Source the shared library | ||
. "$(dirname "$0")/../lib/validate.sh" | ||
|
||
echo "Starting s3 upload script validation" | ||
|
||
check_var SRC_FILE_PATH | ||
check_var DEST_FILE_PATH | ||
check_var S3_ACCESS_KEY | ||
check_var S3_SECRET_KEY | ||
check_var S3_ENDPOINT | ||
check_var S3_REGION | ||
check_var S3_BUCKET | ||
check_var PATH_PREFIX | ||
|
||
SRC_FILE_PATH="/$SRC_FILE_PATH" | ||
|
||
if [ -n "$ARCHIVE_FORMAT" ]; then | ||
if [ -d "$SRC_FILE_PATH" ]; then | ||
cd "$SRC_FILE_PATH" | ||
else | ||
cd "$(dirname "$SRC_FILE_PATH")" | ||
fi | ||
|
||
echo "Archiving $SRC_FILE_PATH" | ||
|
||
ARCHIVED_FILE="/tmp/archive.$ARCHIVE_FORMAT" | ||
|
||
case "$ARCHIVE_FORMAT" in | ||
"tar.gz") | ||
tar -czvf "$ARCHIVED_FILE" "." | ||
;; | ||
"zip") | ||
apk add zip | ||
zip -r "$ARCHIVED_FILE" "." | ||
;; | ||
*) | ||
echo "Unsupported archive format: $ARCHIVE_FORMAT" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
UPLOAD_FILE="$ARCHIVED_FILE" | ||
else | ||
UPLOAD_FILE="$SRC_FILE_PATH" | ||
fi | ||
|
||
echo "Uploading $UPLOAD_FILE to s3://$S3_BUCKET/$PATH_PREFIX/$DEST_FILE_PATH" | ||
|
||
s3cmd --guess-mime-type \ | ||
--access_key "$S3_ACCESS_KEY" \ | ||
--secret_key "$S3_SECRET_KEY" \ | ||
--host "$S3_ENDPOINT" \ | ||
--host-bucket "$S3_ENDPOINT" \ | ||
--region "$S3_REGION" \ | ||
put "$UPLOAD_FILE" "s3://$S3_BUCKET/$PATH_PREFIX/$DEST_FILE_PATH" | ||
|
||
if [ -n "$ARCHIVE_FORMAT" ]; then | ||
echo "Removing $ARCHIVED_FILE" | ||
rm -f "$ARCHIVED_FILE" | ||
fi | ||
|
||
echo "Done" |
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,10 @@ | ||
#!/bin/sh | ||
|
||
# Function to check if a variable is set and not empty | ||
check_var() { | ||
eval value=\$$1 | ||
if [ -z "$value" ]; then | ||
echo "Error: $1 is not set or is empty" | ||
exit 1 | ||
fi | ||
} |