Skip to content

Commit

Permalink
feat: add the copepod action
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarneo committed Nov 16, 2024
1 parent 80cbcc4 commit 42db33d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Deploy to production
uses: bjarneo/workflows/action/copepod/action.yml@master
uses: bjarneo/workflows/action/copepod.yml@main
with:
host: remote_host.com
user: deploy_user
Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:
# Example of rolling back if needed
# NOTE: You want to have a manual approval step in between to ensure you want to rollback
- name: Rollback production
uses: ./.github/action/copepod
uses: bjarneo/workflows/action/copepod.yml@main
with:
host: remote_host.com
user: deploy_user
Expand Down
104 changes: 104 additions & 0 deletions workflows/action/codepod.yml
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

0 comments on commit 42db33d

Please sign in to comment.