Skip to content

Commit

Permalink
padawan - deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
dcordz committed Jan 19, 2025
1 parent 88865c0 commit a6371f6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
9 changes: 4 additions & 5 deletions lib/tasks/sway.rake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ namespace :sway do
google_logger.level = Logger::INFO
Google::Apis.logger = google_logger

Rails.logger.info("sway.rake -> Download seeds file data from Google Cloud, gs://sway-sqlite/seeds/. Uploaded via deploy.sh script.")
download_directory(bucket_name: "sway-sqlite", bucket_directory_name: "seeds", local_directory_name: "/rails/storage")

Rails.logger.info("sway.rake -> Download geojson files from Google Cloud, gs://sway-sqlite/. Uploaded via deploy.sh script.")
download_directory(bucket_name: "sway-sqlite", bucket_directory_name: "geojson", local_directory_name: "/rails/storage")

backup_db
Expand All @@ -24,16 +27,12 @@ namespace :sway do
Rails.logger.info("sway.rake -> backup_db attempt #{attempt}")

if File.exist? "storage/production.sqlite3"
Rails.logger.info("sway.rake -> Uploading production.sqlite3 to google storage as backup.")
Rails.logger.info("sway.rake -> Uploading production.sqlite3 to google storage as backup. Bucket - gs://sway-sqlite/production.sqlite3")
upload_file(bucket_name: "sway-sqlite", bucket_file_path: "production.sqlite3",
local_file_path: "/rails/storage/production.sqlite3")
elsif attempt < 5
sleep 1
backup_db(attempt + 1)
# else
# Rails.logger.info('Getting production.sqlite3 from google storage backup.')
# download_file(bucket_name: 'sway-sqlite', bucket_file_path: 'production.sqlite3',
# local_file_path: 'storage/production.sqlite3')
end
end
end
57 changes: 46 additions & 11 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
#!/usr/bin/env zsh

set -eu

DEPLOY_ENVIRONMENT=${1:-"flyio"}

export $(cat .env.production | xargs)

echo ""
echo "#############################################################################"
echo "deploy.sh -> RAILS_ENV=production bundle install"
echo "#############################################################################"
echo ""
RAILS_ENV=production bundle install

# Build a local image
# docker buildx build . -f docker/dockerfiles/production.dockerfile -t sway:latest --compress

# cp vite.config.ts tmp/vite.config.ts && \
# cp vite.config.build.ts vite.config.ts && \
# RAILS_ENV=production bundle exec bootsnap precompile app/ lib/ && \
# cp tmp/vite.config.ts vite.config.ts
# RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
# gcloud storage cp --recursive $(pwd)/public/* gs://sway-public
echo ""
echo "#############################################################################"
echo "deploy.sh -> RAILS_ENV=test install + rspec"
echo "#############################################################################"
echo ""
RAILS_ENV=test bundle install
RAILS_ENV=test bundle exec rspec

# Clobber assets so they don't get added to the docker build
echo ""
echo "#############################################################################"
echo "deploy.sh -> Clobber rails assets so they don't get added to the docker build"
echo "#############################################################################"
echo ""
SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:clobber
RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:clobber

echo ""
echo "#############################################################################"
echo "deploy.sh -> Copy geojson files to google cloud gs://sway-sqlite/"
echo "#############################################################################"
echo ""
gcloud storage cp --recursive $(pwd)/storage/geojson gs://sway-sqlite/

echo ""
echo "#############################################################################"
echo "deploy.sh -> Copy seed file data to google cloud gs://sway-sqlite/seeds/"
echo "#############################################################################"
echo ""
gcloud storage cp --recursive $(pwd)/storage/seeds/data gs://sway-sqlite/seeds/


if [[ "$1" = "google" ]]; then
if [[ "$DEPLOY_ENVIRONMENT" = "google" ]]; then

./litestream/replicate.sh

Expand All @@ -35,8 +55,18 @@ if [[ "$1" = "google" ]]; then

else
# Store an image of Sway in github
echo ""
echo "#############################################################################"
echo "deploy.sh -> Log into Github Docker Image Registry"
echo "#############################################################################"
echo ""
echo $GITHUB_ACCESS_TOKEN | docker login ghcr.io -u dcordz --password-stdin

echo ""
echo "#############################################################################"
echo "deploy.sh -> Build docker image."
echo "#############################################################################"
echo ""
docker buildx build . \
-f docker/dockerfiles/production.dockerfile \
--platform linux/amd64 \
Expand All @@ -47,5 +77,10 @@ else
--build-arg SENTRY_ORG=$SENTRY_ORG \
--build-arg SENTRY_PROJECT=$SENTRY_PROJECT

echo ""
echo "#############################################################################"
echo "deploy.sh -> Deploy to fly.io"
echo "#############################################################################"
echo ""
fly deploy
fi
2 changes: 0 additions & 2 deletions vite.config.build.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { sentryVitePlugin } from "@sentry/vite-plugin";
import { defineConfig } from "vite";
// import RubyPlugin from "vite-plugin-ruby"
import ReactPlugin from "@vitejs/plugin-react";
import { resolve } from "path";
import RailsPlugin from "vite-plugin-rails";
import console from "console";

export default defineConfig({
plugins: [
Expand Down

0 comments on commit a6371f6

Please sign in to comment.