-
-
Save danieldraper/ea6f99f3fd4baa0e024db77851131b19 to your computer and use it in GitHub Desktop.
Kamal 2.0 + GitHub Actions
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
KAMAL_REGISTRY_PASSWORD=xxxxxxxxxxxxxxxx | |
KAMAL_REGISTRY_USERNAME=xxxxxxxxxxxxxxxx | |
RAILS_MASTER_KEY=$(cat config/master.key) |
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
name: Deploy | |
concurrency: | |
group: production | |
cancel-in-progress: true | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_BUILDKIT: 1 | |
RAILS_ENV: production | |
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} | |
KAMAL_REGISTRY_PASSWORD: ${{ secrets.KAMAL_REGISTRY_PASSWORD }} | |
KAMAL_REGISTRY_USERNAME: ${{ secrets.KAMAL_REGISTRY_USERNAME }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 3.3.1 | |
bundler-cache: true | |
- run: gem install kamal | |
- uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.KAMAL_REGISTRY_USERNAME }} | |
password: ${{ secrets.KAMAL_REGISTRY_PASSWORD }} | |
- name: Set up Docker Buildx for cache | |
uses: docker/setup-buildx-action@v3 | |
- run: kamal version | |
- run: kamal registry login --verbose | |
# Suggestion to use lock release and redeploy after reading comments from others. Deploying two builds could cause locking issues when the first is cancelled. | |
- run: kamal lock release --verbose | |
- run: kamal redeploy --verbose |
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
KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD | |
KAMAL_REGISTRY_USERNAME=$KAMAL_REGISTRY_USERNAME | |
RAILS_MASTER_KEY=$RAILS_MASTER_KEY |
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
<% require "dotenv"; Dotenv.load(".env") %> | |
# Name of your application. Used to uniquely configure containers. | |
service: foobar | |
# Name of the container image. | |
image: username/foobar | |
# Deploy to these servers. | |
servers: | |
web: | |
hosts: | |
- x.x.x.x | |
jobs: | |
hosts: | |
- x.x.x.x | |
cmd: "bundle exec sidekiq -e production -C config/sidekiq.yml" | |
# Enable SSL auto certification via Let's Encrypt (and allow for multiple apps on one server). | |
# Set ssl: false if using something like Cloudflare to terminate SSL (but keep host!). | |
proxy: | |
ssl: false | |
host: xxx.xx | |
app_port: 3000 | |
# Credentials for your image host. | |
registry: | |
username: | |
- KAMAL_REGISTRY_USERNAME | |
password: | |
- KAMAL_REGISTRY_PASSWORD | |
# Configure builder setup. | |
builder: | |
arch: amd64 | |
dockerfile: Dockerfile | |
secrets: | |
- RAILS_MASTER_KEY | |
# Inject ENV variables into containers (secrets come from .kamal/secrets). | |
# | |
env: | |
clear: | |
RAILS_LOG_TO_STDOUT: true | |
REDIS_URL: "redis://foobar-redis:6379/0" | |
secret: | |
- RAILS_MASTER_KEY | |
volumes: | |
- "storage:/rails/storage" | |
accessories: | |
redis: | |
cmd: redis-server --save 60 1 | |
image: redis:7.4 | |
roles: | |
- web | |
directories: | |
- redis:/data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment