Skip to content

Commit b1e6459

Browse files
committed
Replace string substitutions with erb env vars
1 parent 32d9d4e commit b1e6459

3 files changed

Lines changed: 38 additions & 39 deletions

File tree

.github/workflows/build-container.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ on:
1515
# Only update envs here if you need to change them for this workflow
1616
env:
1717
DOCKER_BUILDKIT: 1
18-
KAMAL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
19-
KAMAL_REGISTRY_USERNAME: ${{ github.actor }}
2018
KAMAL_DEPLOY_HOST: ${{ secrets.KAMAL_DEPLOY_HOST }}
2119

2220
jobs:
@@ -95,8 +93,8 @@ jobs:
9593
uses: docker/login-action@v3
9694
with:
9795
registry: ghcr.io
98-
username: ${{ env.KAMAL_REGISTRY_USERNAME }}
99-
password: ${{ env.KAMAL_REGISTRY_PASSWORD }}
96+
username: ${{ github.actor }}
97+
password: ${{ secrets.GITHUB_TOKEN }}
10098

10199
- name: Setup .NET
102100
uses: actions/setup-dotnet@v5

.github/workflows/release.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ on:
1414

1515
env:
1616
DOCKER_BUILDKIT: 1
17-
KAMAL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
18-
KAMAL_REGISTRY_USERNAME: ${{ github.actor }}
1917
SERVICESTACK_LICENSE: ${{ secrets.SERVICESTACK_LICENSE }}
2018

2119
jobs:
@@ -38,25 +36,13 @@ jobs:
3836
echo "HAS_MIGRATIONS=false" >> $GITHUB_ENV
3937
fi
4038
41-
# This step is for the deployment of the templates only, safe to delete
42-
- name: Modify deploy.yml
43-
env:
44-
KAMAL_DEPLOY_IP: ${{ secrets.KAMAL_DEPLOY_IP }}
45-
if: env.KAMAL_DEPLOY_IP != null
46-
run: |
47-
SERVICE_NAME=$(echo "${{ env.repository_name_lower }}" | tr '.' '-')
48-
sed -i "s/service: my-app/service: $SERVICE_NAME/g" config/deploy.yml
49-
sed -i "s#image: my-user/myapp#image: ${{ env.image_repository_name }}#g" config/deploy.yml
50-
sed -i "s/192.168.0.1/${{ secrets.KAMAL_DEPLOY_IP }}/g" config/deploy.yml
51-
sed -i "s/host: my-app.example.com/host: ${{ secrets.KAMAL_DEPLOY_HOST }}/g" config/deploy.yml
52-
sed -i "s/TechStacks/${{ env.repository_name }}/g" config/deploy.yml
5339
5440
- name: Login to GitHub Container Registry
5541
uses: docker/login-action@v3
5642
with:
5743
registry: ghcr.io
58-
username: ${{ env.KAMAL_REGISTRY_USERNAME }}
59-
password: ${{ env.KAMAL_REGISTRY_PASSWORD }}
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
6046

6147
- name: Set up SSH key
6248
uses: webfactory/ssh-agent@v0.9.0
@@ -115,7 +101,7 @@ jobs:
115101
- name: Deploy with Kamal
116102
run: |
117103
kamal lock release -v
118-
kamal server exec --no-interactive 'echo "${{ env.KAMAL_REGISTRY_PASSWORD }}" | docker login ghcr.io -u ${{ env.KAMAL_REGISTRY_USERNAME }} --password-stdin'
104+
kamal server exec --no-interactive 'echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin'
119105
kamal server exec --no-interactive 'docker pull ghcr.io/${{ env.image_repository_name }}:latest'
120106
kamal deploy -P --version latest
121107

config/deploy.yml

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
1-
# Name of your application. Used to uniquely configure containers.
2-
service: techstacks-io
1+
# Kamal deploy config for this repository. Uses environment variables:
2+
# - GITHUB_REPOSITORY (e.g. acme/example.org) - included in GitHub Actions
3+
# - GITHUB_ACTOR (e.g. acme) - included in GitHub Actions
4+
# - GITHUB_TOKEN ($GITHUB_TOKEN) - included in GitHub Actions
5+
# - KAMAL_DEPLOY_IP (e.g. 100.100.100.100) - from GitHub Action Secret
6+
# - KAMAL_DEPLOY_HOST (e.g. example.org) - from GitHub Action Secret
7+
# - POSTGRES_PASSWORD (e.g. random-password) - from GitHub Action Secret
38

4-
# Name of the container image.
5-
image: ghcr.io/netcoreapps/techstacks.io
9+
# Using Environment variables allows re-use of this config for multiple apps.
10+
# Alternatively, they can be replaced with hard-coded values for
11+
12+
# Name of your application. Used to uniquely configure containers. (e.g. example-org)
13+
service: <%= ENV['GITHUB_REPOSITORY'].to_s.split('/').last.tr('.', '-') %>
14+
15+
# Name of the container image. (e.g. ghcr.io/acne/example.org)
16+
image: ghcr.io/<%= ENV['GITHUB_REPOSITORY'].to_s.downcase %>
617

718
# Required for use of ASP.NET Core with Kamal-Proxy.
819
env:
920
clear:
1021
ASPNETCORE_FORWARDEDHEADERS_ENABLED: true
22+
# secrets from ./kamal/secrets
1123
secret:
1224
- SERVICESTACK_LICENSE
1325

1426
# Deploy to these servers.
1527
servers:
16-
# IP address of server, optionally use env variable.
28+
# IP address of server to deploy to. (e.g. 100.100.100.100)
1729
web:
18-
- 192.168.0.1
19-
# - <%= ENV['KAMAL_DEPLOY_IP'] %>
20-
- network: techstacks-io-network
30+
hosts:
31+
- <%= ENV['KAMAL_DEPLOY_IP'] %>
2132

2233
# Enable SSL auto certification via Let's Encrypt (and allow for multiple apps on one server).
2334
# If using something like Cloudflare, it is recommended to set encryption mode
2435
# in Cloudflare's SSL/TLS setting to "Full" to enable end-to-end encryption.
2536
proxy:
2637
ssl: true
27-
host: techstacks.io
38+
# Hostname to proxy. (e.g. example.org)
39+
host: <%= ENV['KAMAL_DEPLOY_HOST'] %>
2840
# kamal-proxy connects to your container over port 80, use `app_port` to specify a different port.
2941
app_port: 8080
3042

@@ -33,32 +45,35 @@ registry:
3345
# Specify the registry server, if you're not using Docker Hub
3446
server: ghcr.io
3547
username:
36-
- KAMAL_REGISTRY_USERNAME
48+
- <%= ENV['GITHUB_ACTOR'] %>
3749

3850
# Always use an access token rather than real password (pulled from .kamal/secrets).
3951
password:
40-
- KAMAL_REGISTRY_PASSWORD
52+
- <%= ENV['GITHUB_TOKEN'] %>
4153

4254
# Configure builder setup.
4355
builder:
4456
arch: amd64
4557

4658
volumes:
47-
- "/opt/docker/techstacks.io/App_Data:/app/App_Data"
59+
- "/opt/docker/<%= ENV['KAMAL_DEPLOY_HOST'] %>/App_Data:/app/App_Data"
4860

4961
accessories:
5062
postgres:
5163
image: postgres
52-
host: 192.168.0.1
53-
network: techstacks-io-network
64+
# IP address of server to deploy accessory to. (e.g. 100.100.100.100)
65+
host: <%= ENV['KAMAL_DEPLOY_IP'] %>
66+
port: "5433:5432"
5467
env:
5568
clear:
56-
POSTGRES_USER: techstacks
57-
POSTGRES_DB: techstacks
69+
# Database username and database name (e.g. example/example)
70+
POSTGRES_USER: <%= ENV['GITHUB_REPOSITORY'].to_s.split('/').last.tr('.', '-').split('-').first %>
71+
POSTGRES_DB: <%= ENV['GITHUB_REPOSITORY'].to_s.split('/').last.tr('.', '-').split('-').first %>
5872
# Optional: only listens inside container
5973
PGDATA: /var/lib/postgresql/data
74+
# secrets from ./kamal/secrets
6075
secret:
6176
- POSTGRES_PASSWORD
6277
directories:
63-
- /opt/docker/techstacks.io/postgres:/var/lib/postgresql/data
64-
- /opt/docker/techstacks.io/initdb.d:/docker-entrypoint-initdb.d
78+
- /opt/docker/<%= ENV['KAMAL_DEPLOY_HOST'] %>/postgres:/var/lib/postgresql/data
79+
- /opt/docker/<%= ENV['KAMAL_DEPLOY_HOST'] %>/initdb.d:/docker-entrypoint-initdb.d

0 commit comments

Comments
 (0)