Skip to content
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
77 changes: 77 additions & 0 deletions .github/actions/deploy-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: 'Deploy Service'
description: 'Pulls a Docker image and starts a service on a remote EC2 instance.'
inputs:
target_app:
description: 'The target application name (used for container naming).'
required: true
publish_port:
description: 'The port to publish the service on.'
required: true
deploy_tag:
description: 'The Docker image tag to deploy.'
required: true
ec2_host:
description: 'The EC2 host address.'
required: true
secret: true
ec2_user:
description: 'The EC2 username.'
required: true
secret: true
ec2_ssh_key:
description: 'The SSH private key for EC2 access.'
required: true
secret: true
aws_access_key_id:
description: 'AWS Access Key ID.'
required: true
secret: true
aws_secret_access_key:
description: 'AWS Secret Access Key.'
required: true
secret: true
aws_region:
description: 'AWS Region.'
required: true
secret: true
aws_ecr_uri:
description: 'AWS ECR URI.'
required: true
secret: true
runs:
using: 'composite'
steps:
- name: Pull Image and Start Service
uses: appleboy/ssh-action@v1
with:
host: ${{ inputs.ec2_host }}
username: ${{ inputs.ec2_user }}
key: ${{ inputs.ec2_ssh_key }}
script: |
set -e
export AWS_ACCESS_KEY_ID=${{ inputs.aws_access_key_id }}
export AWS_SECRET_ACCESS_KEY=${{ inputs.aws_secret_access_key }}

PUBLISH_PORT=${{ inputs.publish_port }}
DEPLOY_TAG=${{ inputs.deploy_tag }}
TARGET_APP=${{ inputs.target_app }}

echo "Logging into AWS ECR..."
aws ecr get-login-password --region ${{ inputs.aws_region }} | docker login --username AWS --password-stdin ${{ inputs.aws_ecr_uri }}

echo "Pulling Docker image..."
docker pull ${{ inputs.aws_ecr_uri }}/$TARGET_APP:$DEPLOY_TAG

echo "Stopping any existing container named $TARGET_APP or using published port $PUBLISH_PORT..."
docker stop $TARGET_APP || true
docker ps --filter "publish=$PUBLISH_PORT" --format "{{.ID}}" | xargs -r docker stop

echo "Removing any existing container named $TARGET_APP or using published port $PUBLISH_PORT..."
docker rm $TARGET_APP || true
docker ps -a --filter "publish=$PUBLISH_PORT" --format "{{.ID}}" | xargs -r docker rm

echo "Starting new Docker container..."
docker run -d --name $TARGET_APP -p $PUBLISH_PORT:8080 --restart unless-stopped --env-file .env ${{ inputs.aws_ecr_uri }}/$TARGET_APP:$DEPLOY_TAG

echo "Pruning unused Docker objects..."
docker system prune -f
31 changes: 31 additions & 0 deletions .github/actions/latest_tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'Get Latest Git Tag'
inputs:
target:
description: 'build target tag prefix'
required: true
outputs:
latest_tag:
description: 'The latest tag for target'
value: ${{ steps.get_tag.outputs.latest_tag }}
runs:
using: 'composite'
steps:
- id: get_tag
outputs:
latest_tag:
run: |
TARGET_APP="${{ inputs.target }}"

# Get latest tag for build target
LATEST_TAG=$(git tag -l "${TARGET_APP}" | sort -V | tail -n 1)

if [ -z "$LATEST_TAG" ]; then
echo "No existing tags found for ${TARGET_APP}. Initializing with v0.0.0"
CURRENT_TAG="${TARGET_APP}/v0.0.0"
else
echo "Latest tag for ${TARGET_APP}: $LATEST_TAG"
CURRENT_TAG="$LATEST_TAG"
fi

echo "latest_tag=$CURRENT_TAG"
echo "latest_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
48 changes: 48 additions & 0 deletions .github/actions/semver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'Version Bump'
inputs:
version:
description: 'Semver formatted version'
required: true
bump:
description: 'major, minor, or patch'
required: true
outputs:
next_version:
description: 'The next version'
value: ${{ steps.version_bump.outputs.next_version }}
runs:
using: 'composite'
steps:
- id: version_bump
shell: bash
env:
VERSION: ${{ inputs.version }}
BUMP: ${{ inputs.bump }}
run: |
# Strip all characters that aren't part of the semver section
VERSION=$(echo "$VERSION" | tr -dc '0-9.')

# Parse in semver
IFS='.' read -r major minor patch <<< "$VERSION"

case "$BUMP" in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
*)
echo "Invalid bump type. Must be major, minor, or patch."
exit 1
;;
esac

NEXT_VERSION="$major.$minor.$patch"
echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
2 changes: 0 additions & 2 deletions .github/workflows/deploy-auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ on:
jobs:
trigger-build-and-deploy:
uses: ./.github/workflows/deploy-base.yml
with:
dry_run: false
secrets: inherit
Loading