Skip to content

Latest commit

 

History

History
180 lines (116 loc) · 3.86 KB

README.md

File metadata and controls

180 lines (116 loc) · 3.86 KB

Rails Academy: Lesson 103 - Deploying your first Rails application

In this lesson you will deploy rails to a real server.

You can use this free server* for the other lessons or anything you want.

Topics

  • DockerHub
  • Kamal

Prerequisites

Lesson 101

1. Install the Rails Academy GitHub app

If you have not added your ssh keys from lesson 101 yet, please do so now.

Once you see a successful message, you can continue to the next step.

2. Get into the lesson repository

First, let's make sure we are in the correct directory:

cd ~/lessons/ra-103

If you don't have the lesson, clone the repo.

gh repo clone ~/lessons/ra-103

Next, we'll create a personal branch to work out of named after your Github username:

git checkout -b YOUR_GITHUB_USERNAME

A quick way to get your Github username is to run:

gh api user --jq '.login'

After that you should see a terminal like:

~/lessons/ra-103 [github_username]
$ _

3. Signup for DockerHub

Username

  • Signup for a free account or login to DockerHub
  • Go to your Account Settings
  • Copy your username from the top left next to your avatar or empty profile pic
  • Open ~/config/deploy in your editor and add the following
# Name of the container image.
image: my-dockerhub-username/ra_103

And below also add your DockerHub username:

# Credentials for your image host.
registry:
  # Specify the registry server, if you're not using Docker Hub
  # server: registry.digitalocean.com / ghcr.io / ...
  username: my-dockerhub-username

API Key

  • Click on Personal Access Tokens
  • Generate a new token with the following permissions (Read, Write Delete)
  • Open ./.kamal/secrets in your editor and add the following
KAMAL_REGISTRY_PASSWORD=your-personal-access-token

Note:: This is not the most secure way to store your secrets, but it is the easiest for this lesson.

4. Configure Kamal to deploy your application

Now that you have your changes saved to git, you can deploy your application to a real server.

In config/deploy.rb.

Update the server line to be:

servers:
  web:
    - your-github-username.rails.academy

Also change the proxy settings to:

proxy:
  ssl: true
  host: your-github-username.rails.academy

And finally uncomment and set your user to your Github username:

# Use a different ssh user than root
ssh:
  user: your-github-username

Finally run the following command to configure Kamal:

kamal config

If you see an error check deploy.yml for mistakes.

5. Generate a local rails master.key

EDITOR=nano rails credentials:edit

Save your changes by pressing Ctrl + X and then Y to confirm.

This will generate a private key in config/master.key required for rails to run.

6. Commit your changes to git

git add .
git commit -m "Added DockerHub and Kamal configuration"

7. 🚀 Deploy your application 🚀

kamal deploy

If you don't see any errors you can now see your app running on the web.

https://your-github-username.rails.academy

🎉 You should see your application running. 🎉

9. Create a Pull Request

gh pr create
  • Visit your PR on Github.

The automatic check will run if your code passes, you'll see:

✅ All checks have passed

🎉 You're Done! 🎉

Additional Resources