-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
3 changed files
with
128 additions
and
110 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 |
---|---|---|
@@ -1,42 +1,61 @@ | ||
#!/bin/bash | ||
|
||
# Print the input parent directories and difference output | ||
echo "PARENT_DIRS=$PARENT_DIRS" | ||
echo "DIFF_OUTPUT=$DIFF_OUTPUT" | ||
|
||
# Get tags from the input parameters | ||
TAG=$1 | ||
CN_TAG=$2 | ||
|
||
# Read the differences and parent directories into arrays | ||
IFS=',' read -r -a DIFF_OUTPUT_ARRAY <<< "$DIFF_OUTPUT" | ||
IFS=',' read -r -a PARENT_DIRS_ARRAY <<< "$PARENT_DIRS" | ||
|
||
# Print the contents of the arrays for debugging | ||
echo "DIFF_OUTPUT array: ${DIFF_OUTPUT_ARRAY[@]}" | ||
echo "PARENT_DIRS array: ${PARENT_DIRS_ARRAY[@]}" | ||
|
||
# Function to build and push Docker images | ||
build_and_push_image() { | ||
local dockerfile_path=$1 | ||
local image_name=$2 | ||
|
||
docker buildx build --push \ | ||
--file "$dockerfile_path" \ | ||
--platform linux/amd64 \ | ||
--tag "ghcr.io/$USERNAME/devbox/$image_name" \ | ||
. | ||
} | ||
|
||
# Iterate over Dockerfile paths | ||
for i in "${!DIFF_OUTPUT_ARRAY[@]}"; do | ||
DOCKERFILE_PATH=${DIFF_OUTPUT_ARRAY[$i]} | ||
PARENT_DIR=${PARENT_DIRS_ARRAY[$i]} | ||
|
||
# Extract parent path for further use | ||
parent_path="${DOCKERFILE_PATH%/*}" | ||
parent_path=$(dirname "$parent_path") | ||
|
||
IFS='/' read -ra ADDR <<< $DOCKERFILE_PATH | ||
PARENT_DIR=${PARENT_DIRS_ARRAY[$i]} | ||
# Create the English image name | ||
IFS='/' read -ra ADDR <<< "$DOCKERFILE_PATH" | ||
EN_IMAGE_NAME="${ADDR[1]}-$PARENT_DIR:$TAG" | ||
|
||
# Build and push the English Docker image | ||
build_and_push_image "$DOCKERFILE_PATH" "$EN_IMAGE_NAME" | ||
|
||
docker buildx build --push \ | ||
--file $DOCKERFILE_PATH \ | ||
--platform linux/amd64\ | ||
--tag "ghcr.io/$USERNAME/devbox/$EN_IMAGE_NAME" \ | ||
. | ||
|
||
# Check for the Chinese Dockerfile update script and handle accordingly | ||
if [ -f "$parent_path/update_cn_dockerfile.sh" ]; then | ||
bash "$parent_path/update_cn_dockerfile.sh" $DOCKERFILE_PATH | ||
CN_IMAGE_NAME="${ADDR[1]}-$PARENT_DIR:$CN_TAG" | ||
docker buildx build --push \ | ||
--file $DOCKERFILE_PATH"tmp" \ | ||
--platform linux/amd64\ | ||
--tag "ghcr.io/$USERNAME/devbox/$CN_IMAGE_NAME" \ | ||
. | ||
bash "$parent_path/update_cn_dockerfile.sh" "$DOCKERFILE_PATH" | ||
CN_IMAGE_NAME="${ADDR[1]}-$PARENT_DIR:$CN_TAG" | ||
|
||
# Use a temporary Dockerfile for the Chinese image | ||
TEMP_DOCKERFILE="${DOCKERFILE_PATH}tmp" | ||
|
||
# Build and push the Chinese Docker image | ||
build_and_push_image "$TEMP_DOCKERFILE" "$CN_IMAGE_NAME" | ||
|
||
rm $DOCKERFILE_PATH"tmp" | ||
# Remove the temporary Dockerfile | ||
rm "$TEMP_DOCKERFILE" | ||
fi | ||
done | ||
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
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 |
---|---|---|
@@ -1,23 +1,40 @@ | ||
#!/bin/bash | ||
|
||
DIFF_OUTPUT=$(git diff --name-only "$1" "$2"|grep Dockerfile) | ||
# Check the number of input parameters | ||
if [ "$#" -ne 2 ]; then | ||
echo "Usage: $0 <commit1> <commit2>" | ||
exit 1 | ||
fi | ||
|
||
# Get the list of Dockerfile differences between the two commits | ||
DIFF_OUTPUT=$(git diff --name-only "$1" "$2" | grep Dockerfile) | ||
|
||
# Initialize arrays to store parent directories and file paths | ||
PARENT_DIRS=() | ||
FILE_PATHS=() | ||
|
||
# Iterate over the changed files | ||
for FILE_PATH in $DIFF_OUTPUT; do | ||
# Check if the file exists | ||
if [[ ! -f "$FILE_PATH" ]]; then | ||
echo "File $FILE_PATH does not exist, skipping." | ||
echo "File '$FILE_PATH' does not exist, skipping." | ||
continue | ||
fi | ||
PARENT_DIR=$(dirname "$FILE_PATH" | awk -F'/' '{print $(NF)}') | ||
|
||
# Get the name of the parent directory of the file | ||
PARENT_DIR=$(basename "$(dirname "$FILE_PATH")") | ||
PARENT_DIRS+=("$PARENT_DIR") | ||
FILE_PATHS+=("$FILE_PATH") | ||
done | ||
|
||
# Convert arrays to comma-separated strings | ||
PARENT_DIRS_STRING=$(IFS=,; echo "${PARENT_DIRS[*]}") | ||
DIFF_OUTPUT_STRING=$(IFS=,; echo "${FILE_PATHS[*]}") | ||
|
||
# Print results to the console | ||
echo "PARENT_DIRS=$PARENT_DIRS_STRING" | ||
echo "DIFF_OUTPUT=$DIFF_OUTPUT_STRING" | ||
|
||
echo "PARENT_DIRS=$PARENT_DIRS_STRING" >> $GITHUB_ENV | ||
echo "DIFF_OUTPUT=$DIFF_OUTPUT_STRING" >> $GITHUB_ENV | ||
# Write results to environment variables | ||
echo "PARENT_DIRS=$PARENT_DIRS_STRING" >> "$GITHUB_ENV" | ||
echo "DIFF_OUTPUT=$DIFF_OUTPUT_STRING" >> "$GITHUB_ENV" |