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.
- DockerHub
- Kamal
If you have not added your ssh keys from lesson 101 yet, please do so now.
- Login to your GitHub account
- Install the Rails Academy GitHub App
Once you see a successful message, you can continue to the next step.
First, let's make sure we are in the correct directory:
cd ~/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]
$ _
- 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.yml
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
- 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.
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.
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.
git add .
git commit -m "Added DockerHub and Kamal configuration"
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. 🎉
gh pr create
- Visit your PR on Github.
The automatic check will run if your code passes, you'll see:
✅ All checks have passed