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

Ft/deployment setup #66

Merged
merged 68 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
37e5029
add deploy to staging workflow
thepsalmist Mar 27, 2024
a5c799d
add Makefile
thepsalmist Mar 27, 2024
0fddb92
update compose file
thepsalmist Mar 27, 2024
c9a06b7
update Dockerhub access creds
thepsalmist Mar 27, 2024
fb80d20
use appleboy ssh action master
thepsalmist Mar 27, 2024
7a3c95c
fix cache
thepsalmist Mar 27, 2024
2ec820f
fix registry
thepsalmist Mar 27, 2024
24d8df0
fix registry & envs
thepsalmist Mar 27, 2024
8b540f7
lint fix
thepsalmist Mar 27, 2024
50fe458
refactor deploy setup
thepsalmist Mar 28, 2024
7d16f65
fix deploy setup
thepsalmist Mar 28, 2024
f7dc522
lint
thepsalmist Apr 2, 2024
b05ebb7
cfa dockerhub
thepsalmist Apr 2, 2024
2993707
rm deprecated set_outpu
thepsalmist Apr 2, 2024
293cee7
fix source from private repo
thepsalmist Apr 3, 2024
3ad061e
compose tag variable
thepsalmist Apr 3, 2024
d69225e
update: apply feedback
thepsalmist Apr 4, 2024
3e0da20
Merge branch 'ft/deployment-setup' into staging
thepsalmist Apr 4, 2024
487de80
cfa docker
thepsalmist Apr 4, 2024
7f816cc
update: refactor release workflow
thepsalmist Apr 8, 2024
c0025dc
update: refactor release workflow
thepsalmist Apr 8, 2024
bfb1ed3
update: fixes for IMAGE taging
thepsalmist Apr 8, 2024
0b9d4dd
cleanup: MC dockerhub variable names
thepsalmist Apr 8, 2024
0928402
cleanup: source ESHOSTS from config repo
thepsalmist Apr 8, 2024
331029d
updates: cleanup from feedback
thepsalmist Apr 11, 2024
badbfc7
updates: update Makefile
thepsalmist Apr 12, 2024
7d96c20
updates: update Makefile
thepsalmist Apr 12, 2024
0e1ba02
updates: update deploy.sh get image tag
thepsalmist Apr 12, 2024
765cd95
update: modify Makefile for dev
thepsalmist Apr 17, 2024
0e205bb
Update README.md
thepsalmist Apr 30, 2024
b050ab8
Update Makefile
thepsalmist Apr 30, 2024
f3bbfb7
apply updates
thepsalmist Apr 30, 2024
394ab89
apply updates
thepsalmist Apr 30, 2024
428ee17
add staging file
thepsalmist Apr 30, 2024
f8554a1
fix clone
thepsalmist Apr 30, 2024
3ed7d83
fix clone
thepsalmist Apr 30, 2024
98939c4
cleanup & fixes, update docker compose
thepsalmist Apr 30, 2024
b4ffaa8
fixes, update docker compose envs
thepsalmist Apr 30, 2024
10e5ad8
fix pep440
thepsalmist Apr 30, 2024
a751a1d
rm pep440
thepsalmist Apr 30, 2024
7453cbb
update pep440 versioning
thepsalmist May 2, 2024
6e66269
update pep440 versioning, pattern-raw
thepsalmist May 2, 2024
9cf6b86
fix ESOPTS
thepsalmist May 2, 2024
e3488c4
update deploy.sh for dev deployment
thepsalmist May 3, 2024
8486f28
update: makefile sudo permissions & cleanup
thepsalmist May 8, 2024
9181e92
feedback
thepsalmist May 15, 2024
4a02c5a
update: dev deploy not require tag
thepsalmist May 20, 2024
f0af60a
update: dev deploy not require tag
thepsalmist May 20, 2024
3a0f652
update: add -a tag, for deploy without git tag
thepsalmist May 22, 2024
0d61c24
add SENTRY
thepsalmist May 23, 2024
51563c5
add dev.sh file
thepsalmist May 23, 2024
ead0f90
cleanup
thepsalmist May 23, 2024
01652db
add enhancements
thepsalmist May 23, 2024
7680452
update docs
thepsalmist May 23, 2024
b278551
update docs
thepsalmist May 23, 2024
70ba25b
Update README.md
thepsalmist May 24, 2024
8d24846
Update deploy.sh
thepsalmist May 24, 2024
59b5b6d
Update docs/deployment.md
thepsalmist May 24, 2024
678fa06
Update docs/deployment.md
thepsalmist May 24, 2024
d6c5124
Update docs/deployment.md
thepsalmist May 24, 2024
7175e69
Update Makefile
thepsalmist May 24, 2024
bdf4b19
apply updates
thepsalmist May 24, 2024
36733f0
use repo compose file
thepsalmist May 24, 2024
b4e5331
Update docs/deployment.md
thepsalmist May 24, 2024
678cc78
Update docs/deployment.md
thepsalmist May 24, 2024
1418daa
Update docs/deployment.md
thepsalmist May 24, 2024
54d5c0d
Update docs/deployment.md
thepsalmist May 24, 2024
e415d26
Update docs/deployment.md
thepsalmist May 24, 2024
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
27 changes: 22 additions & 5 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ name: Build Docker Image for Every Tag

on:
push:
branches:
- 'staging'
thepsalmist marked this conversation as resolved.
Show resolved Hide resolved
tags:
- '**'
env:
IMAGE_NAME: "mcsystems/news-search-api"
BETA_VERSION: "b1"

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 +33,25 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha
type=raw,value=staging-${{ env.BETA_VERSION }},enable=${{ endsWith(github.ref, 'staging') }}

- 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: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
#registry defaults to dockerhub
thepsalmist marked this conversation as resolved.
Show resolved Hide resolved
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: build up down

build:
docker-compose build

up:
thepsalmist marked this conversation as resolved.
Show resolved Hide resolved
docker-compose up -d

down:
docker-compose down

publish:
docker push mcsystems/news-search-api:staging

bash:
docker-compose exec api bash
118 changes: 118 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash
thepsalmist marked this conversation as resolved.
Show resolved Hide resolved
# deploy.sh - Deployment script for News Search API and UI

# Environment variables

IMAGE_TAG="latest" # Change this based on deployment (staging, production, v1.0)
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"
APP_NAME="news-search-api"

# Check if running as root
is_root() {
thepsalmist marked this conversation as resolved.
Show resolved Hide resolved
if [ $(whoami) != "root" ]; then
echo "This script must be run as root."
exit 1
fi
}

is_root
echo "Running as root"

LOGIN_USER=$(who am i | awk '{ print $1 }')
if [ "x$LOGIN_USER" = x ]; then
# XXX fall back to whoami (look by uid)
echo could not find login user 1>&2
exit 1
fi

run_as_login_user() {
thepsalmist marked this conversation as resolved.
Show resolved Hide resolved
is_root
su $LOGIN_USER -c "$*"
}

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"
}

zzz() {
echo $1 | tr 'A-Za-z' 'N-ZA-Mn-za-m'
}

# 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_config"
rm -rf "$PRIVATE_CONF_DIR"
mkdir -p "$PRIVATE_CONF_DIR"
chmod go-rwx "$PRIVATE_CONF_DIR"
CONFIG_REPO_PREFIX=$(zzz tvg@tvguho.pbz:zrqvnpybhq)
CONFIG_REPO_NAME=$(zzz arjf-frnepu-ncv-pbasvt)
echo cloning $CONFIG_REPO_NAME repo 1>&2
if ! run_as_login_user "git clone $CONFIG_REPO_PREFIX/$CONFIG_REPO_NAME.git" >/dev/null 2>&1; then
echo "FATAL: could not clone config repo" 1>&2
thepsalmist marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi
PRIVATE_CONF_REPO=$(pwd)/$CONFIG_REPO_NAME
PRIVATE_CONF_FILE=$PRIVATE_CONF_REPO/$APP_NAME.sh
cd ..

if [ ! -f $PRIVATE_CONF_FILE ]; then
echo "FATAL: could not access $PRIVATE_CONF_FILE" 1>&2
exit 1
fi
#source private conf to load SENTRY_DSN
thepsalmist marked this conversation as resolved.
Show resolved Hide resolved
. $PRIVATE_CONF_FILE


INSTALL_DIR="news_search_api"
mkdir -p "$INSTALL_DIR"

GH_REPO_PREFIX="https://github.com/mediacloud"
GH_REPO_NAME="news-search-api"
DOCKER_COMPOSE_FILE="docker-compose.yml"
echo "Fetching $DOCKER_COMPOSE_FILE from $GH_REPO_NAME repo..."
if ! curl -sSfL "$GH_REPO_PREFIX/$GH_REPO_NAME/raw/$IMAGE_TAG/$DOCKER_COMPOSE_FILE" -o "$INSTALL_DIR/$DOCKER_COMPOSE_FILE"; then
echo "FATAL: Could not fetch $DOCKER_COMPOSE_FILE from config repo"
exit 1

fi

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

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

echo "Deployment completed successfully!"
15 changes: 7 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
services:
api:
image: mcsystems/news-search-api
image: mcsystems/news-search-api:${IMAGE_TAG}
build: .
ports:
- 8000:8000
networks:
- story-indexer
- new-search-api
volumes:
- .:/app

ui:
image: mcsystems/news-search-api
image: mcsystems/news-search-api:${IMAGE_TAG}
build: .
environment:
APIURL: http://api:8000/v1
ports:
- 8001:8501
- 8501:8501
networks:
- story-indexer
- new-search-api
volumes:
- .:/app
depends_on:
- api
command: streamlit run ui.py

networks:
thepsalmist marked this conversation as resolved.
Show resolved Hide resolved
story-indexer:
name: story-indexer
external: true
new-search-api:
name: new-search-api