# Sliplane Deploy

Sliplane is now my favorite hosting provider, it is very easy to deploy and you can have several apps under the same server, great if your apps haven't picked up momentum without having to spend hundreds of $ on Heroku servers.

***

After doing the setup, Sliplane’s mental model is:

1. **Create a Server** (your machine)
2. **Create a Project** (a group for one app and its services)
3. Add services inside the project (Postgres, Redis, your Rails app from GitHub)
4. Add env vars, deploy, then optionally add a custom domain
5. Use the built-in console (SSH) when you need to run Rails commands

{% hint style="info" %}
Bonus: **you can host several apps on the same server**, which is awesome for keeping costs down. Each app is just another Project on that same Server.
{% endhint %}

***

### 0. Prerequisites

* Your Lightning Rails app is pushed to GitHub (main branch recommended)
* You have a Sliplane account
* You are ready to set production env vars (Cloudinary, OpenAI, Stripe, etc if your app uses them) from your `.env` file

***

### 1. Prepare your app (Choose based on your case)

<details>

<summary>💡 <strong>For updating existing apps</strong></summary>

```
# One-time setup (if not already done)
gh auth login

# Fetch the Sliplane setup files and add them to your project

# 1. Fetch the rake task
gh api repos/LightningRails/lightning-rails/contents/lib/tasks/sliplane_setup.rake \
  --jq '.content' | base64 -d > lib/tasks/sliplane_setup.rake

# 2. Fetch the bash script
gh api repos/LightningRails/lightning-rails/contents/bin/setup-sliplane \
  --jq '.content' | base64 -d > bin/setup-sliplane

# 3. Make the bash script executable
chmod +x bin/setup-sliplane

# 4. Commit the changes
git add lib/tasks/sliplane_setup.rake bin/setup-sliplane
git commit -m "Added Sliplane deployment setup"

# 5. You're ready to deploy!
rails sliplane:setup
```

</details>

<details>

<summary><strong>🆕 For a new app</strong></summary>

From your project root:

```
bin/rails sliplane:setup
```

</details>

This command will:

* Create a production-ready `Dockerfile`
* Create `.dockerignore`
* Create `bin/docker-entrypoint`
* Create `.env.example`
* Generate a `SECRET_KEY_BASE`
* Print all required environment variables
* Show the Sliplane deployment checklist

Then push your code:

```
git add .
git commit -m "Prepare for Sliplane"
git push origin main
```

That’s it on the code side.

***

### 2. Create a Server in Sliplane

1. Go to Sliplane
2. Click **Create Server**
3. Choose a region
4. Choose an instance size (start small, scale later)
5. Wait until the server is ready

You can deploy multiple apps on the same server by creating multiple Projects.

***

### 3. Create a Project (your app)

1. Click **Create Project**
2. Name it something like:

```
myapp-production
```

Inside this project, you’ll add services.

***

### 4. Add a PostgreSQL service (Required)

Inside your project:

1. Click **Add Service**
2. Choose **PostgreSQL**
3. Set it to **Private** (not public) ⚠️
4. Add a Volume (Leave default)
5. Set (Leave default):

* `POSTGRES_USER`
* `POSTGRES_PASSWORD` (mark as Secret)
* `POSTGRES_DB`

6. Add&#x20;

Deploy it.

Once live, note the variables above and the internal hostname\
You’ll need it for `DATABASE_URL`.

***

### 5. Add Redis (Optional)

If your app uses:

* Caching
* ActionCable
* Very complex Background jobs
* Sidekiq

Then:

1. Add Service → Redis
2. Set to **Private**
3. Add a volume (optional)
4. Deploy

If not, you can skip this and use a SolidQueue setup (Guide coming soon)

***

### 6. Add Your Rails App (Repository Service)

Inside your project:

1. Click **Add Service**
2. Choose **Repository**
3. Connect your GitHub repo
4. Select branch (usually `main` or `master`)
5. Sliplane will detect your `Dockerfile`
6. ⚠️ Make sure the privacy toggle is set to TRUE! Or you won't be able to add a domain.

Set (Default):

* Public: **Enabled**
* Protocol: **HTTP**
* Healthcheck path: `/`

Deploy.

Sliplane will now build your Docker image and compile assets.

***

### 7. Add Environment Variables

Go to your Rails service → Settings → Environment Variables.

Add all the variables found in your `.env` file.

#### Required

```
RAILS_ENV=production
SECRET_KEY_BASE="Find this key in the terminal when you ran the script"
RAILS_SERVE_STATIC_FILES=true
RAILS_LOG_TO_STDOUT=true
```

#### Database URL

Go to your PostgreSQL service and find the variables in "settings". Here is where we link our brand new PostgreSQL service with our brand new repository service.

Build it using your Postgres service:

```
postgresql://USER:PASSWORD@INTERNAL_HOST_URL:5432/DB_NAME
```

Example shape:

```
postgresql://app_user:superSecret123@postgres-lhlg.internal:5432/production_db
```

Add it as:

```
DATABASE_URL=...
```

***

#### Third-Party Keys (if your app uses them)

If your Lightning Rails app uses external services, add them here:

Examples:

* `CLOUDINARY_URL`
* `OPENAI_API_KEY`
* `STRIPE_PUBLIC_KEY`
* `STRIPE_SECRET_KEY`
* `POSTMARK_API_TOKEN`

If it exists in your `.env` locally or in your previous hosting provider's config, it likely belongs here in production.

***

### 8. First Deploy Checklist

Once deployed:

* Visit your Sliplane URL (`*.sliplane.app`)
* Confirm styles are loading
* Test login / registration
* Check logs if anything fails

If styles are missing, make sure:

```
RAILS_SERVE_STATIC_FILES=true
```

is set.

***

### 9. Add a Custom Domain (Private Domain)

To use your own domain:

1. Open your Rails service
2. Go to **Domains**
3. Add your domain (example: `app.yourdomain.com`)
4. Sliplane will show required DNS records

Usually:

* For subdomain → create a **CNAME**
* For root domain → follow the exact record Sliplane provides

Once DNS propagates, SSL is handled automatically.

You can then update:

```
RAILS_HOST=app.yourdomain.com
```

in environment variables if needed.

***

### 10. Open Console (SSH)

Useful for:

* Running migrations
* Seeding data
* Rails console

#### Step 1 – Add your SSH key

In Sliplane account settings, add your public SSH key.

#### Step 2 – Open the service console

In your Rails service, click **Console / SSH**.\
Sliplane provides a ready-to-copy SSH command.

Use that command.

#### Step 3 – Navigate to the app directory

```
cd /your-app
```

#### Step 4 – Run commands

```
bundle exec rails db:migrate
bundle exec rails db:seed
bundle exec rails c
```

***

<details>

<summary>💡 Migrate PostgreSQL DB from Heroku (Optional)</summary>

We assume:

* Heroku app has a Postgres addon
* Sliplane has an internal Postgres service (like `postgres-lhlg.internal:5432`)
* You can run commands locally (recommended)

***

## Phase 1 — Freeze Heroku

### 1️⃣ Put Heroku in maintenance mode

```
heroku maintenance:on -a YOUR_HEROKU_APP
```

This prevents new writes while you migrate.

***

### 2️⃣ Take final backup (insurance)

```
heroku pg:backups:capture -a YOUR_HEROKU_APP
heroku pg:backups:download -a YOUR_HEROKU_APP
```

You now have `latest.dump` locally.

Keep it safe.

***

## Phase 2 — Restore to Sliplane

(You already did this, but here’s the official version)

### 3️⃣ Use pg\_restore 17 locally

```
PGPASSWORD='YOUR_DB_PASSWORD' $(brew --prefix postgresql@17)/bin/pg_restore \
  --verbose \
  --clean --if-exists \
  --no-owner --no-privileges \
  -h YOUR_PUBLIC_DB_HOST \
  -p YOUR_PUBLIC_DB_PORT \
  -U postgres \
  -d mydb \
  latest.dump
```

Let it finish.

***

### 4️⃣ Verify restore

```
PGPASSWORD='YOUR_DB_PASSWORD' psql \
  -h YOUR_PUBLIC_DB_HOST \
  -p YOUR_PUBLIC_DB_PORT \
  -U postgres \
  -d mydb \
  -c "\dt"
```

Then test row counts:

```
select count(*) from users;
```

Match with Heroku:

```
heroku run rails console -a YOUR_HEROKU_APP
User.count
```

If counts match → DB migration successful.

***

## Phase 3 — Point Rails to Sliplane DB

Now update your Sliplane Rails service:

Use **internal DB URL** (important for security & performance):

```
postgresql://postgres:PASSWORD@postgres-q6uu.internal:5432/mydb
```

Set this as:

```
DATABASE_URL
```

in Sliplane environment variables.

***

### 5️⃣ Redeploy Rails app

Then test:

* Login works
* New records save
* Background jobs work
* Stripe webhooks work
* Emails send
* ActiveStorage works

Create a test record and delete it.

***

## Phase 4 — Switch Traffic

If not already done:

* Update DNS to Sliplane
* Wait propagation
* Confirm production domain works

Monitor logs for 10–15 minutes.

***

## Phase 5 — Lock Down Database

Very important.

Once everything works:

* Remove public DB access
* Remove `0.0.0.0/0`
* Make Postgres internal-only

Your Rails app should now talk only via internal hostname.

***

## Phase 6 — Kill Heroku (After Confidence Window)

Leave Heroku in maintenance mode for a few hours (optional safety buffer).

When ready:

```
heroku apps:destroy -a YOUR_HEROKU_APP
```

Also remove:

* Heroku Postgres addon
* Heroku Redis
* Any scheduler addons

Double-check nothing else depends on it.

</details>

### Cost Optimization Tip

You can host **multiple Lightning Rails apps on the same Sliplane server**.

Each app:

* Has its own Project
* Has its own Postgres service
* Shares the same server resources

This keeps infrastructure simple and affordable.

***

### Summary

Deploying Lightning Rails to Sliplane is:

1. Run one setup command
2. Create server
3. Add Postgres
4. Add Repository service
5. Paste env variables
6. Deploy

Clean, simple, production-ready.
