Skip to content
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

Add container deployment pipeline #32

Merged
merged 1 commit into from
May 18, 2024
Merged
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
37 changes: 37 additions & 0 deletions .github/workflows/docker_container_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Deploy to DROPLET

on:
workflow_dispatch:
inputs:
image_tag:
description: 'Choose a tag:'
required: true
type: string
default: 'latest'

jobs:
deploy:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Convert Repository Name to Lowercase
run: |
lowercase_name=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]')
echo "lowercase_repo_name=$lowercase_name" >> $GITHUB_ENV

- name: Deploy infra to DROPLET
uses: appleboy/ssh-action@master
with:
passphrase: ${{ secrets.SSH_PASSPHRASE }}
host: ${{ secrets.DROPLET_HOST }}
username: ${{ secrets.DROPLET_USERNAME }}
key: ${{ secrets.DROPLET_KEY }}
script: |
docker container ls -q --filter name=trumpee-${{ env.lowercase_repo_name }}:${{ github.event.inputs.image_tag }} > /tmp/current_container_id || true # Get the container ID if it exists
if [ -s /tmp/current_container_id ]; then # Check if previous container exists and is running
docker stop $(cat /tmp/current_container_id) || true # Stop the old container
docker rm $(cat /tmp/current_container_id) || true # Remove the old container
fi

docker pull ghcr.io/trumpee/trumpee-${{ env.lowercase_repo_name }}:${{ github.event.release.tag_name}}
docker run -d -p 5217:8080 --name trumpee-${{ env.lowercase_repo_name }}:${{ github.event.inputs.image_tag }} ghcr.io/trumpee/trumpee-${{ env.lowercase_repo_name }}:${{ github.event.release.tag_name}}
Loading