Skip to content

Commit

Permalink
Add a GitHub Action workflow to deploy the demo automatically
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Aug 23, 2024
1 parent eb0541e commit fb87d8c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly.io Demo Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
MYSQL_CONNECTION_URL: ${{ secrets.MYSQL_CONNECTION_URL }}
PLAUSIBLE_DOMAIN: ${{ secrets.PLAUSIBLE_DOMAIN }}
run: |
flyctl secrets set --stage MYSQL_CONNECTION_URL=${MYSQL_CONNECTION_URL} PLAUSIBLE_DOMAIN=${PLAUSIBLE_DOMAIN}
flyctl deploy --remote-only
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,5 @@ Cargo.lock
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Deployment
config.dev.toml
fly.toml
fly.dev.toml

# Others
.DS_Store
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ WORKDIR /usr/src/app
# output directory before the cache mounted /app/target is unmounted.
RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,target=/app/target/ \
--mount=type=cache,target=/usr/local/cargo/registry/ \
<<EOF
set -e
cargo build --locked --release
cargo build --release
EOF

################################################################################
Expand Down
7 changes: 3 additions & 4 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ port = 5299

[meta]
blog_name = "rsomhaP"
blog_url = "http://0.0.0.0:5299"
blog_url = "https://rsomhap.fly.dev"
blog_author = "JmPotato"
# You can customize the about page URL.
# about_url = "https://about.ipotato.me"
about_url = "https://github.com/JmPotato/rsomhaP"

[admin]
# The admin username used to login to the admin page.
# Its password is the same as the username, so please change it after deploying ASAP.
username = "admin"
username = "rsomhaP"
# The number of inactive days that the admin session will be expired.
inactive_expiry_days = 30

Expand Down
27 changes: 27 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# fly.toml app configuration file generated for rsomhap on 2024-08-22T01:06:04+08:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "rsomhap"
primary_region = "nrt"

[http_service]
auto_start_machines = true
auto_stop_machines = "suspend"
force_https = true
internal_port = 5_299
min_machines_running = 0
processes = ["app"]

[[http_service.checks]]
grace_period = "10s"
interval = "30s"
method = "GET"
timeout = "5s"
path = "/ping"

[[vm]]
cpu_kind = "shared"
cpus = 1
memory = "512mb"
15 changes: 14 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,25 @@ pub struct Config {
impl Config {
pub fn new(path: &str) -> Result<Self, Error> {
let config_content = std::fs::read_to_string(path).unwrap();
let config: Self = toml::from_str(&config_content).map_err(Error::Toml)?;
let mut config: Self = toml::from_str(&config_content).map_err(Error::Toml)?;
// get some environment variables.
config.load_env_vars()?;
// validate the config to ensure the deployment is correct.
config.validate()?;

Ok(config)
}

fn load_env_vars(&mut self) -> Result<(), Error> {
if let Ok(mysql_connection_url) = std::env::var("MYSQL_CONNECTION_URL") {
self.mysql.connection_url = Some(mysql_connection_url);
}
if let Ok(plausible_domain) = std::env::var("PLAUSIBLE_DOMAIN") {
self.analytics.plausible = Some(plausible_domain);
}
Ok(())
}

pub fn validate(&self) -> Result<(), Error> {
// check the deployment config.
if self.deploy.host.is_empty() || self.deploy.port == 0 {
Expand Down

0 comments on commit fb87d8c

Please sign in to comment.