-
Notifications
You must be signed in to change notification settings - Fork 7
108 lines (104 loc) · 3.36 KB
/
Copy pathbuild_deploy.yml
File metadata and controls
108 lines (104 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Build and Deploy
on:
push:
branches:
- main
pull_request:
types: [synchronize, opened]
schedule:
- cron: '15 2 * * *' # Reset demo daily at 2:15 UTC
workflow_dispatch:
inputs:
environment:
type: environment
required: true
default: production
concurrency:
group: build-${{ github.ref_name }}
cancel-in-progress: ${{ github.ref_name != 'main' }}
jobs:
Build:
runs-on: ubuntu-latest
env:
IMAGE_NAME: ghcr.io/alchemycms/alchemy-demo
steps:
- name: Check out the repo
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Expose GitHub Runtime for cache
uses: crazy-max/ghaction-github-runtime@v3
- name: Set Alchemy Version
run: |
version=$(awk '/^ alchemy_cms \(/ { gsub(/[()]/, "", $2); print $2 }' "Gemfile.lock")
echo "ALCHEMY_VERSION=$version" >> "$GITHUB_ENV"
- name: Show Alchemy Version
run: echo "Current Alchemy Version ${{ env.ALCHEMY_VERSION }}"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: $
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
pull: true
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.IMAGE_NAME }}:${{ env.ALCHEMY_VERSION }}
${{ env.IMAGE_NAME }}:${{ github.sha }}
${{ env.IMAGE_NAME }}:latest
labels: |
service=alchemy-demo
cache-from: type=gha
cache-to: type=gha,mode=max
Deploy:
runs-on: ubuntu-latest
needs: Build
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
environment:
name: production
url: https://demo.alchemy-cms.com
env:
KAMAL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
ADMIN_LOGIN: ${{ secrets.ADMIN_LOGIN }}
ADMIN_EMAIL: ${{ secrets.ADMIN_EMAIL }}
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
CLOUDINARY_URL: ${{ secrets.CLOUDINARY_URL }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
VERSION: ${{ github.sha }}
steps:
- name: Check out the repo
uses: actions/checkout@v5
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Setup SSH
uses: webfactory/ssh-agent@v0.9.1
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Deploy with Kamal
id: deploy
continue-on-error: true
run: |
set -o pipefail
bin/kamal deploy --skip-push --version=$VERSION 2>&1 | tee /tmp/kamal-deploy.log
- name: Reboot kamal-proxy and retry deploy
if: steps.deploy.outcome == 'failure'
run: |
if grep -q "kamal-proxy.*is too old" /tmp/kamal-deploy.log; then
echo "kamal-proxy is outdated, rebooting..."
bin/kamal proxy reboot -y
bin/kamal deploy --skip-push --version=$VERSION
else
echo "Deploy failed for a different reason"
exit 1
fi