Skip to content

Commit

Permalink
refactor deploy setup
Browse files Browse the repository at this point in the history
  • Loading branch information
thepsalmist committed Mar 28, 2024
1 parent 8b540f7 commit 50fe458
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 70 deletions.
65 changes: 0 additions & 65 deletions .github/workflows/deploy-to-staging.yml

This file was deleted.

23 changes: 18 additions & 5 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ name: Build Docker Image for Every Tag

on:
push:
branches:
- 'staging'
tags:
- '**'
env:
IMAGE_NAME: "mcsystems/news-search-api"

jobs:

build:

runs-on: ubuntu-latest

steps:

- name: Checkout Version
uses: actions/checkout@v4

- name: Dump tag name
run: echo "Building tag ${{github.ref_name}}"
run: echo "Building ${{ github.ref_type }} ${{ github.ref_name }}"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -31,10 +32,22 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Determine Tag
id: tag
run: |
if [ "${{ github.ref_type }}" = "tag" ] && [ "${{ github.ref }}" != "refs/heads/staging" ]; then
echo "::set-output name=tag_name::${{ github.ref_name }}"
else
echo "::set-output name=tag_name::staging"
fi
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: mcsystems/news-search-api:${{github.ref_name}}
tags: ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag_name }}
#registry defaults to dockerhub
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
75 changes: 75 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
# deploy.sh - Deployment script for News Search API and UI

# Environment variables

IMAGE_TAG="staging" # Change this based on your use case
INDEXES="mc_search"
ESHOSTS="http://ramos.angwin:9200,http://woodward.angwin:9200,http://bradley.angwin:9200"
ESOPTS="{'timeout': 60, 'max_retries': 3}" # 'timeout' parameter is deprecated
ELASTICSEARCH_INDEX_NAME_PREFIX="mc_search-*"
TERMFIELDS="article_title,text_content"
TERMAGGRS="top,significant,rare"

# Check if running as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
exit 1
fi

help()
{
echo "Usage: ./deploy.sh [options]"
echo "Options:"
echo "-h show help message"
echo "-t specify the image tag (staging, release, v1.3.1 e.t.c)"
}

log()
{
echo "$1"
}
# Parse command-line options
while getopts :h:t optname; do
log "Option $optname set with value ${OPTARG}"
case $optname in
t)
IMAGE_TAG=${OPTARG}
;;
h)
help
exit 2
;;
*)
echo "Invalid option: $1"
help
exit 2
;;
esac
done

# Create a directory for private configuration
PRIVATE_CONF_DIR="/news_search_api"
rm -rf "$PRIVATE_CONF_DIR"
mkdir -p "$PRIVATE_CONF_DIR"
chmod go-rwx "$PRIVATE_CONF_DIR"

# Fetch the docker-compose.yml file from GitHub
CONFIG_REPO_PREFIX="https://github.com/mediacloud" # Replace with your actual GitHub URL
CONFIG_REPO_NAME="news-search-api" # Change to your actual repo name
DOCKER_COMPOSE_FILE="docker-compose.yml" # Name of the Docker Compose file
echo "Fetching $DOCKER_COMPOSE_FILE from $CONFIG_REPO_NAME repo..."
if ! curl -sSfL "$CONFIG_REPO_PREFIX/$CONFIG_REPO_NAME/raw/main/$DOCKER_COMPOSE_FILE" -o "$PRIVATE_CONF_DIR/$DOCKER_COMPOSE_FILE"; then
echo "FATAL: Could not fetch $DOCKER_COMPOSE_FILE from config repo"
exit 1ls

fi

# Deploy services using Docker Compose
echo "Deploying services with image tag: $IMAGE_TAG"
docker-compose -f "$PRIVATE_CONF_DIR/$DOCKER_COMPOSE_FILE" up -d

# Additional steps (e.g., database migrations, cache clearing, etc.)
# ...

echo "Deployment completed successfully!"

0 comments on commit 50fe458

Please sign in to comment.