-
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
Showing
2 changed files
with
106 additions
and
2 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
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,104 @@ | ||
name: Deploy with Copepod | ||
|
||
description: 'Deploy applications using Copepod' | ||
|
||
inputs: | ||
host: | ||
description: 'Remote host to deploy to' | ||
required: true | ||
user: | ||
description: 'SSH user for remote host' | ||
required: false | ||
default: 'root' | ||
image: | ||
description: 'Docker image name' | ||
required: true | ||
dockerfile: | ||
description: 'Path to the dockerfile' | ||
required: false | ||
default: 'Dockerfile' | ||
tag: | ||
description: 'Docker image tag' | ||
required: false | ||
default: 'latest' | ||
platform: | ||
description: 'Docker platform' | ||
required: false | ||
default: 'linux/amd64' | ||
ssh_key: | ||
description: 'SSH private key content' | ||
required: true | ||
container_name: | ||
description: 'Name for the container' | ||
required: true | ||
container_port: | ||
description: 'Container port' | ||
required: true | ||
host_port: | ||
description: 'Host port' | ||
required: true | ||
env_file: | ||
description: 'Environment file' | ||
required: false | ||
build_args: | ||
description: 'Build arguments (comma-separated KEY=VALUE pairs)' | ||
required: false | ||
rollback: | ||
description: 'Rollback to the previous version' | ||
required: false | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Set up SSH key | ||
shell: bash | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "${{ inputs.ssh_key }}" > ~/.ssh/deploy_key | ||
chmod 600 ~/.ssh/deploy_key | ||
ssh-keyscan -H ${{ inputs.host }} >> ~/.ssh/known_hosts | ||
- name: Download Copepod | ||
shell: bash | ||
run: | | ||
curl -L -o copepod "https://github.com/bjarneo/copepod/releases/latest/download/copepod-linux-amd64" | ||
chmod +x copepod | ||
- name: Prepare build args | ||
id: build_args | ||
shell: bash | ||
run: | | ||
BUILD_ARGS="" | ||
if [ -n "${{ inputs.build_args }}" ]; then | ||
IFS=',' read -ra ARGS <<< "${{ inputs.build_args }}" | ||
for arg in "${ARGS[@]}"; do | ||
BUILD_ARGS="$BUILD_ARGS --build-arg $arg" | ||
done | ||
fi | ||
echo "args=$BUILD_ARGS" >> $GITHUB_OUTPUT | ||
- name: Deploy with Copepod | ||
shell: bash | ||
env: | ||
HOST: ${{ inputs.host }} | ||
HOST_USER: ${{ inputs.user }} | ||
HOST_PLATFORM: ${{ inputs.platform }} | ||
HOST_PORT: ${{ inputs.host_port }} | ||
DOCKER_IMAGE_NAME: ${{ inputs.image }} | ||
DOCKER_IMAGE_TAG: ${{ inputs.tag }} | ||
DOCKER_CONTAINER_NAME: ${{ inputs.container_name }} | ||
DOCKER_CONTAINER_PORT: ${{ inputs.container_port }} | ||
DOCKER_CONTAINER_ENV_FILE: ${{ inputs.env_file }} | ||
run: | | ||
if [ "${{ inputs.rollback }}" = "true" ]; then | ||
./copepod --rollback | ||
else | ||
./copepod ${{ steps.build_args.outputs.args }} | ||
fi | ||
- name: Upload deployment logs | ||
if: always() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: deployment-logs | ||
path: copepod_deployment.log |