Skip to content

Deploy to Test

Deploy to Test #88

# =============================================================================
# Deploy to Test
# =============================================================================
# Manually triggered workflow to deploy a version to test environment.
# Requires semantic version tag (v1.2.3).
# Creates Git tag and GitHub Release if this is a new version.
# Also rebuilds typesense-sync image to keep it in lockstep.
# =============================================================================
name: Deploy to Test
on:
workflow_dispatch:
inputs:
version:
description: 'Version tag (e.g., v1.2.3)'
required: true
type: string
permissions: write-all
env:
OPENSHIFT_NAMESPACE_TOOLS: 6cdc9e-tools
OPENSHIFT_NAMESPACE_TEST: 6cdc9e-test
IMAGE_NAME: eagle-api
SYNC_IMAGE_NAME: typesense-sync
CRON_IMAGE_NAME: eagle-cron
APP_NAME: eagle-api
jobs:
validate:
name: Validate Version
runs-on: ubuntu-latest
outputs:
tag_exists: ${{ steps.check-tag.outputs.exists }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Validate version format
run: |
if [[ ! "${{ inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format v1.2.3"
exit 1
fi
- name: Check if tag exists
id: check-tag
run: |
if git rev-parse "${{ inputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag ${{ inputs.version }} already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag ${{ inputs.version }} does not exist - will create"
fi
release:
name: Create Release
needs: validate
if: needs.validate.outputs.tag_exists == 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Create Git tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ inputs.version }}" -m "Release ${{ inputs.version }}"
git push origin "${{ inputs.version }}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ inputs.version }}" \
--title "Release ${{ inputs.version }}" \
--generate-notes
deploy:
name: Deploying ${{ inputs.version }} to Test
needs: [validate, release]
if: always() && needs.validate.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout repository at version tag
uses: actions/checkout@v6
with:
ref: ${{ inputs.version }}
- name: Install OpenShift CLI
run: |
curl -LO "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux.tar.gz"
tar -xvzf openshift-client-linux.tar.gz
sudo mv oc /usr/local/bin/
rm -f openshift-client-linux.tar.gz
- name: Log into OpenShift
run: oc login --token=${{ secrets.OPENSHIFT_TOKEN }} --server=${{ secrets.OPENSHIFT_URL }}
- name: Check if image exists and tag if needed
run: |
if oc -n ${{ env.OPENSHIFT_NAMESPACE_TOOLS }} get imagestreamtag ${{ env.IMAGE_NAME }}:${{ inputs.version }} &>/dev/null; then
echo "Image tag ${{ inputs.version }} already exists - using existing image"
else
echo "Image tag ${{ inputs.version }} does not exist - tagging from ci-latest"
oc -n ${{ env.OPENSHIFT_NAMESPACE_TOOLS }} tag \
${{ env.IMAGE_NAME }}:ci-latest ${{ env.IMAGE_NAME }}:${{ inputs.version }}
fi
- name: Tag version as test
run: |
echo "Tagging ${{ inputs.version }} as test..."
oc -n ${{ env.OPENSHIFT_NAMESPACE_TOOLS }} tag \
${{ env.IMAGE_NAME }}:${{ inputs.version }} ${{ env.IMAGE_NAME }}:test
- name: Install Helm
run: |
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
helm version
- name: Deploy with Helm
run: |
helm upgrade --install ${{ env.APP_NAME }} ./helm/${{ env.APP_NAME }} \
--namespace ${{ env.OPENSHIFT_NAMESPACE_TEST }} \
--values ./helm/${{ env.APP_NAME }}/values-test.yaml \
--set image.tag=test \
--wait --timeout=5m
- name: Verify deployment
run: |
echo "Deployment successful!"
oc get pods -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} -l app.kubernetes.io/name=${{ env.APP_NAME }}
# Verify MongoDB deployment if enabled
if oc get deployment eagle-api-mongodb -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} &>/dev/null; then
echo ""
echo "Verifying MongoDB deployment..."
oc rollout status deployment/eagle-api-mongodb -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} --timeout=3m
echo "✓ MongoDB deployment verified"
fi
build-cron:
name: Build Cron Image
needs: [validate, release]
if: always() && needs.validate.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout repository at version tag
uses: actions/checkout@v6
with:
ref: ${{ inputs.version }}
- name: Login to OpenShift registry
uses: docker/login-action@v4
with:
registry: ${{ secrets.OPENSHIFT_REPOSITORY }}
username: ${{ secrets.OPENSHIFT_REPOSITORY_USERNAME }}
password: ${{ secrets.OPENSHIFT_REPOSITORY_PASSWORD }}
- name: Build and push cron image
uses: docker/build-push-action@v7
with:
context: ./openshift/templates/jobs/cron/docker
push: true
tags: |
${{ secrets.OPENSHIFT_REPOSITORY }}/${{ env.OPENSHIFT_NAMESPACE_TOOLS }}/${{ env.CRON_IMAGE_NAME }}:test
${{ secrets.OPENSHIFT_REPOSITORY }}/${{ env.OPENSHIFT_NAMESPACE_TOOLS }}/${{ env.CRON_IMAGE_NAME }}:${{ inputs.version }}
build-sync:
name: Build Sync Image
runs-on: ubuntu-latest
steps:
- name: Checkout repository at version tag
uses: actions/checkout@v6
with:
ref: ${{ inputs.version }}
- name: Login to OpenShift registry
uses: docker/login-action@v4
with:
registry: ${{ secrets.OPENSHIFT_REPOSITORY }}
username: ${{ secrets.OPENSHIFT_REPOSITORY_USERNAME }}
password: ${{ secrets.OPENSHIFT_REPOSITORY_PASSWORD }}
- name: Build and push sync image
uses: docker/build-push-action@v7
with:
context: ./typesense-sync
push: true
tags: |
${{ secrets.OPENSHIFT_REPOSITORY }}/${{ env.OPENSHIFT_NAMESPACE_TOOLS }}/${{ env.SYNC_IMAGE_NAME }}:test
${{ secrets.OPENSHIFT_REPOSITORY }}/${{ env.OPENSHIFT_NAMESPACE_TOOLS }}/${{ env.SYNC_IMAGE_NAME }}:${{ inputs.version }}
deploy-sync:
name: Deploy Sync to Test
needs: [deploy, build-sync]
runs-on: ubuntu-latest
steps:
- name: Checkout repository at version tag
uses: actions/checkout@v6
with:
ref: ${{ inputs.version }}
- name: Install OpenShift CLI
run: |
curl -LO "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux.tar.gz"
tar -xvzf openshift-client-linux.tar.gz
sudo mv oc /usr/local/bin/
rm -f openshift-client-linux.tar.gz
- name: Install Helm
run: |
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
helm version
- name: Log into OpenShift
run: oc login --token=${{ secrets.OPENSHIFT_TOKEN }} --server=${{ secrets.OPENSHIFT_URL }}
- name: Upgrade Typesense chart
run: |
helm upgrade --install typesense ./helm/typesense \
--namespace ${{ env.OPENSHIFT_NAMESPACE_TEST }} \
--values ./helm/typesense/values-test.yaml \
--wait --timeout=5m
- name: Restart sync deployment
run: |
echo "Restarting typesense-sync deployment to pick up new image..."
if oc get deployment typesense-typesense-sync -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} &>/dev/null; then
oc rollout restart deployment/typesense-typesense-sync -n ${{ env.OPENSHIFT_NAMESPACE_TEST }}
oc rollout status deployment/typesense-typesense-sync -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} --timeout=3m
echo "✓ Sync deployment restarted"
else
echo "⚠ typesense-sync deployment not found — skipping"
fi