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

First pass at redeploy script for CD #2

Merged
merged 1 commit into from
Aug 22, 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
26 changes: 26 additions & 0 deletions script/cd-redeploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Change directory to the bookworm folder
cd /opt/bookworm
# Stash any local changes
git stash
# Checkout main branch if not already on it
git checkout main
# Pull any changes
git pull
# Stop and remove containers
docker compose down
# Remove locally built images
echo "Deleting locally built Docker images"
docker image rm $(docker images "bookworm-**" -q)
# Delete app volume
echo "Deleting app volume"
# Build containers
echo "Building docker images"
docker compose build
# Restart containers
echo "Restarting Docker containers"
docker compose up -d
# Run Database migrations if necessary
echo "Running Database Migrations"
docker exec -i $(docker ps --filter name=rails -q) bash -lc "bundle exec rails db:migrate RAILS_ENV=production"