-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continuous deployment to fly.io (#41)
* Add script to register app name * Set scale to 1 * Add pre-commit to check app name registered or not * Add deploy job and use flyctl command * Rename workflow file
- Loading branch information
1 parent
709a8fd
commit a3852fd
Showing
8 changed files
with
113 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
{{cookiecutter.project_slug}}/.github/workflows/deploy_to_fly_io.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% raw %} | ||
name: Fly Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: superfly/flyctl-actions/setup-flyctl@master | ||
|
||
- name: Check if the app name is registered in fly.io | ||
run: ./scripts/deploy_to_fly_io.sh | ||
|
||
- name: Deploy to Fly | ||
run: | | ||
flyctl deploy --remote-only --config fly.toml --yes | ||
flyctl scale count 1 --config fly.toml --yes | ||
flyctl secrets set OPENAI_API_KEY=$OPENAI_API_KEY | ||
env: | ||
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}{% endraw %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
{{cookiecutter.project_slug}}/scripts/check-registered-app-pre-commit.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
# taken from: https://jaredkhan.com/blog/mypy-pre-commit | ||
|
||
# A script for running mypy, | ||
# with all its dependencies installed. | ||
|
||
set -o errexit | ||
|
||
# Change directory to the project root directory. | ||
cd "$(dirname "$0")"/.. | ||
|
||
./scripts/check-registered-app.sh |
8 changes: 8 additions & 0 deletions
8
{{cookiecutter.project_slug}}/scripts/check-registered-app.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
# Check file registered_app_domain.txt exists. If it does not exists, echo and exit. | ||
if [ ! -f registered_app_domain.txt ]; then | ||
echo -e "\033[0;33mWarning: App name is not registered.\033[0m" | ||
echo -e "\033[0;33mGithub Actions may fail if you push without registering.\033[0m" | ||
echo -e "\033[0;33mRegister your app name by running the script 'scripts/register_to_fly_io.sh'.\033[0m" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
#!/bin/bash | ||
|
||
echo -e "\033[0;32mLogging into fly.io\033[0m" | ||
fly auth login | ||
# Check file registered_app_domain.txt exists. If it does not exists, echo and exit. | ||
if [ ! -f registered_app_domain.txt ]; then | ||
echo -e "\033[0;31mError: App name is not registered.\033[0m" | ||
echo -e "\033[0;31mRegister your app name by running the script 'scripts/register_to_fly_io.sh'.\033[0m" | ||
echo -e "\033[0;31mExiting.\033[0m" | ||
exit 1 | ||
fi | ||
|
||
echo -e "\033[0;32mChecking if already logged into fly.io\033[0m" | ||
if ! flyctl auth whoami > /dev/null 2>&1; then | ||
echo -e "\033[0;32mLogging into fly.io\033[0m" | ||
flyctl auth login | ||
else | ||
echo -e "\033[0;32mAlready logged into fly.io\033[0m" | ||
fi | ||
|
||
echo -e "\033[0;32mDeploying to fly.io\033[0m" | ||
fly launch --config fly.toml --copy-config --yes | ||
flyctl deploy --config fly.toml --yes | ||
flyctl scale count 1 --config fly.toml --yes | ||
|
||
echo -e "\033[0;32mSetting secrets\033[0m" | ||
fly secrets set OPENAI_API_KEY=$OPENAI_API_KEY | ||
flyctl secrets set OPENAI_API_KEY=$OPENAI_API_KEY |
32 changes: 32 additions & 0 deletions
32
{{cookiecutter.project_slug}}/scripts/register_to_fly_io.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
|
||
# Check file registered_app_domain.txt exists. If it does, echo and exit. | ||
if [ -f registered_app_domain.txt ]; then | ||
echo -e "\033[1;33mWarning: App name is already registered.\033[0m" | ||
echo -e "\033[0;32mRegistered app name is:\033[0m" | ||
cat registered_app_domain.txt | ||
exit 1 | ||
fi | ||
|
||
echo -e "\033[0;32mChecking if already logged into fly.io\033[0m" | ||
if ! flyctl auth whoami > /dev/null 2>&1; then | ||
echo -e "\033[0;32mLogging into fly.io\033[0m" | ||
flyctl auth login | ||
else | ||
echo -e "\033[0;32mAlready logged into fly.io\033[0m" | ||
fi | ||
|
||
export FLY_APP_NAME={{ cookiecutter.project_slug.replace("_", "-") }} | ||
|
||
echo -e "\033[0;32mRegistering app name in fly.io\033[0m" | ||
if flyctl apps create $FLY_APP_NAME; then | ||
echo "$FLY_APP_NAME.fly.dev" > registered_app_domain.txt | ||
echo -e "\033[0;32mApp name registered successfully\033[0m" | ||
echo -e "\033[0;32mRegistered app name is:\033[0m" | ||
cat registered_app_domain.txt | ||
else | ||
echo -e "\033[1;31mError: App name is not available.\033[0m" | ||
echo -e "\033[1;31mPlease change the app name in fly.toml and scripts/register_to_fly_io.sh and run this script again.\033[0m" | ||
exit 1 | ||
fi |