Skip to content

Instantly share code, notes, and snippets.

@kyrylo
Created September 13, 2024 10:56
Show Gist options
  • Save kyrylo/9d669c90be0c4984543d3a7c4bf1397c to your computer and use it in GitHub Desktop.
Save kyrylo/9d669c90be0c4984543d3a7c4bf1397c to your computer and use it in GitHub Desktop.
Deploy with Kamal and GitHub Actions
name: Deploy
on:
push:
branches:
- main
jobs:
Deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: 1
RAILS_ENV: production
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.KAMAL_REGISTRY_USER }}
password: ${{ secrets.DOCKER_REGISTRY_KEY }}
- name: Set Tag
id: tag
run: |
echo "tag=$(git rev-parse "$GITHUB_SHA")" >> $GITHUB_OUTPUT
- name: Build image
uses: docker/build-push-action@v5
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
push: true
labels: |
"service=telebugs"
tags: |
"${{ secrets.KAMAL_REGISTRY_USER }}/telebugs:latest"
"${{ secrets.KAMAL_REGISTRY_USER }}/telebugs:${{ steps.tag.outputs.tag }}"
cache-from: type=gha
cache-to: type=gha,mode=max
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Install kamal
run: gem install kamal
- name: Deploy
run: kamal deploy --skip-push
env:
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
KAMAL_REGISTRY_PASSWORD: ${{ secrets.DOCKER_REGISTRY_KEY }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment