Skip to content

feat: implement develop/main branch structure #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ main ]
branches: [ main, develop ]
pull_request:
branches: [ main ]
branches: [ main, develop ]

jobs:
shellcheck:
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
types: [closed]
branches:
- main
- develop

jobs:
update-changelog:
Expand All @@ -20,7 +21,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
ref: ${{ github.base_ref }}
token: ${{ secrets.PAT_TOKEN }}

- name: Get PR title and body
Expand Down Expand Up @@ -156,7 +157,8 @@ jobs:
git config --global user.name "github-actions[bot]"

# Create branch and commit changes with error handling
BRANCH_NAME="bot/update-changelog-v${NEW_VERSION}"
TARGET_BRANCH="${{ github.base_ref }}"
BRANCH_NAME="bot/update-changelog-v${NEW_VERSION}-${TARGET_BRANCH}"
if ! git checkout -b "$BRANCH_NAME"; then
echo "Error: Failed to create new branch"
exit 1
Expand Down Expand Up @@ -185,13 +187,14 @@ jobs:
### Changes
- Type: ${CHANGE_TYPE}
- Original PR Title: ${PR_TITLE}
- Target Branch: ${TARGET_BRANCH}

This is an automated update by the changelog workflow."

if ! gh pr create \
--title "docs: update changelog for v${NEW_VERSION}" \
--body "$PR_BODY" \
--base main \
--base "$TARGET_BRANCH" \
--head "$BRANCH_NAME"; then
echo "Warning: Failed to create PR, but changes were pushed to branch"
fi
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,45 @@ Logs are stored in:

## Development

### Branch Structure

This repository follows a simplified GitFlow workflow with two main branches:

- `main`: The stable branch containing production-ready code
- All releases are tagged from this branch
- Protected branch requiring PR reviews
- Must pass all CI checks before merging

- `develop`: The development branch where features are integrated
- All feature branches merge here first
- Contains latest development changes
- Must pass CI checks before merging

#### Working with Branches

1. Feature Development
```bash
git checkout develop
git checkout -b feature/your-feature
# Make your changes
git push origin feature/your-feature
# Create PR to develop
```

2. Bug Fixes
```bash
git checkout develop
git checkout -b fix/bug-description
# Fix the bug
git push origin fix/bug-description
# Create PR to develop
```

3. Release Process
- Features are merged into `develop`
- When ready for release, `develop` is merged into `main`
- Release tags are created from `main`

### Project Management

This project uses GitHub's project management features to track issues, pull requests, and milestones. We follow a structured workflow:
Expand Down
83 changes: 44 additions & 39 deletions startup_docker_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ SHUTDOWN_LIST="shutdowned.txt"

log_message() {
local message="$1"
local level="${2:-INFO}" # Default level is INFO
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] $message" | tee -a "$LOG_FILE"
echo "[$timestamp] [$level] $message" | tee -a "$LOG_FILE"
}

# Function to check container status
Expand All @@ -25,6 +26,19 @@ check_container() {
fi
}

# Function to get container details
get_container_details() {
local name=$1
local details=$(docker inspect "$name" 2>/dev/null)
if [ $? -eq 0 ]; then
local ip=$(echo "$details" | grep -m 1 '"IPAddress":' | cut -d '"' -f 4)
local created=$(echo "$details" | grep -m 1 '"Created":' | cut -d '"' -f 4)
echo "IP: $ip, Created: $created"
else
echo "No details available"
fi
}

# Function to reverse file content (compatible with both macOS and Linux)
reverse_file() {
if command -v tac >/dev/null 2>&1; then
Expand All @@ -36,66 +50,57 @@ reverse_file() {

# Check if shutdown list exists
if [ ! -f "$SHUTDOWN_LIST" ]; then
log_message "No shutdown list found at $SHUTDOWN_LIST. Nothing to start."
log_message "No shutdown list found at $SHUTDOWN_LIST. Nothing to start." "WARNING"
exit 1
fi

log_message "Starting Docker containers from shutdown list..."
log_message "Starting Docker containers from shutdown list..." "INFO"

# Read the shutdown list in reverse order (to respect dependencies)
while IFS='|' read -r name image cmd ports networks; do
log_message "Processing container: $name"
log_message "Processing container: $name" "INFO"

# Check container status
container_status=$(check_container "$name")

case $container_status in
case "$container_status" in
"running")
log_message "Container $name is already running, skipping..."
continue
log_message "Container $name is already running" "INFO"
details=$(get_container_details "$name")
log_message "Container details - $details" "INFO"
;;
"stopped")
log_message "Container $name exists but is stopped, starting it..."
log_message "Starting stopped container: $name" "INFO"
if docker start "$name"; then
log_message "Successfully started existing container: $name"
details=$(get_container_details "$name")
log_message "Successfully started container $name" "SUCCESS"
log_message "Container details - $details" "INFO"
else
log_message "Failed to start existing container: $name"
log_message "Failed to start container $name" "ERROR"
fi
continue
;;
"none")
# Process port mappings
port_args=""
if [ ! -z "$ports" ]; then
# Convert semicolon-separated port mappings into multiple -p arguments
for port_mapping in ${ports//;/ }; do
if [ ! -z "$port_mapping" ]; then
port_args="$port_args -p $port_mapping"
fi
done
fi

# Process network
network_arg=""
if [ ! -z "$networks" ]; then
# Get first network (before semicolon)
network=$(echo "$networks" | cut -d';' -f1)
if [ ! -z "$network" ]; then
network_arg="--network $network"
fi
fi

log_message "Creating new container: $name" "INFO"
# Create and start the container
docker_cmd="docker run -d --name ${name} ${port_args} ${network_arg} ${image} ${cmd}"
log_message "Creating new container: $docker_cmd"

if eval "$docker_cmd"; then
log_message "Successfully created and started container: $name"
if [ -z "$networks" ]; then
if docker run -d --name "$name" $ports "$image" $cmd; then
details=$(get_container_details "$name")
log_message "Successfully created and started container $name" "SUCCESS"
log_message "Container details - $details" "INFO"
else
log_message "Failed to create container $name" "ERROR"
fi
else
log_message "Failed to create and start container: $name"
if docker run -d --name "$name" $ports --network "$networks" "$image" $cmd; then
details=$(get_container_details "$name")
log_message "Successfully created and started container $name with network $networks" "SUCCESS"
log_message "Container details - $details" "INFO"
else
log_message "Failed to create container $name with network $networks" "ERROR"
fi
fi
;;
esac
done < <(reverse_file "$SHUTDOWN_LIST")

log_message "Finished starting all containers from shutdown list."
log_message "Container startup process completed" "INFO"
Loading