My rails application has the following
- Dockerfile
- config/deploy.yml
- .env
I am trying to do
kamal env push
INFO [55b3675b] Running /usr/bin/env mkdir -p .kamal on ${SERVER_IP}
ERROR (Socket::ResolutionError): Exception while executing on host ${SERVER_IP}: getaddrinfo: No such host is known.
Whatever I do, I am not able to get kamal resolve my variables from .env
file, it works if I hard code all the variables into the deploy.yml
itself
What am I doing wrong? I have no clue how to debug as well.
In fact even when I am trying to give path for my private key which is in my ~.sshid_rsa
, it is not able to find it! I had to put the private key itself in my deploy.yml
to make it work.
( I am using git bash
in windows)
My deploy.yml looks like this
# Name of your application. Used to uniquely configure containers.
service: myapp
# Name of the container image.
image: ${DOCKER_USERNAME}/myapp
# Deploy to these servers.
servers:
web:
- ${SERVER_IP}
# Credentials for your image host.
registry:
username:
- ${DOCKER_USERNAME}
password:
- ${DOCKER_PASSWORD}
# Inject ENV variables into containers.
env:
clear:
REDIS_URL: ${REDIS_URL}
DOMAIN: ${DOMAIN}
secret:
- RAILS_MASTER_KEY
- LETSENCRYPT_EMAIL
# Use accessory services.
accessories:
redis:
image: redis:7-alpine
host: ${SERVER_IP}
port: 6379
# Configure custom arguments for Traefik.
traefik:
args:
entryPoints.web.address: ":80"
entryPoints.websecure.address: ":443"
certificatesResolvers.letsencrypt.acme.email: ${LETSENCRYPT_EMAIL}
certificatesResolvers.letsencrypt.acme.storage: "/letsencrypt/acme.json"
certificatesResolvers.letsencrypt.acme.httpChallenge.entryPoint: "web"
options:
publish:
- "443:443"
volume:
- "/letsencrypt:/letsencrypt"
# Configure a custom healthcheck
healthcheck:
path: /up
port: 3000
asset_path: /rails/public
boot:
limit: 25%
wait: 5
ssh:
user: root
keys:
- ${SSH_PRIVATE_KEY_PATH}
2
Answers
Technically,
env
variables are only used inside of your containers. If you want to interpolate them intodeploy.yml
file itself you have to use erb:https://kamal-deploy.org/docs/commands/env/
Try using this syntax: