Skip to content

Host: Deploy latest release tag to production #234

Host: Deploy latest release tag to production

Host: Deploy latest release tag to production #234

name: "Host: Deploy latest release tag to production"
on:
workflow_dispatch:
inputs:
start_choice:
type: choice
description: "Start container"
options:
- 'true'
- 'false'
env:
REGISTRY: ghcr.io
LATEST_VERSION_TAG: ""
REPO: ""
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup environment variables
run: echo "REPO=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get lastest image version tag
run: |
set -ex
USERNAME=${{ github.actor }}
TOKEN=${{ secrets.GITHUB_TOKEN }}
registry_token=$(curl -u $USERNAME:$TOKEN -s https://${{ env.REGISTRY }}/token\?scope\="repository:${{ env.REPO }}:pull" | jq -r .token)
echo "registry_token: $registry_token"
latest_version_tag=$(curl -s -H "Authorization: Bearer $registry_token" "https://${{ env.REGISTRY }}/v2/${{ env.REPO }}/tags/list?n=999999999" | jq -r '.tags[]' | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$" | sort -V | tail -n1)
echo "latest_version_tag: $latest_version_tag"
echo "LATEST_VERSION_TAG=$latest_version_tag" >> $GITHUB_ENV
- name: Deploy Docker Image
uses: ./.github/actions/host/deploy-image-to-environment
with:
image_name: ghcr.io/${{ github.repository }}:${{ env.LATEST_VERSION_TAG }}
env_name: 'production'
force_update: 'true'
start_container: ${{ github.event.inputs.start_choice }}
ansible_host: ${{ secrets.ANSIBLE_HOST }}
ansible_username: ${{ secrets.ANSIBLE_USERNAME }}
ansible_ssh_key: ${{ secrets.ANSIBLE_SSH_KEY }}