Kamal deployment: error "No such file or directory" with mysql

387 views Asked by At

I'm trying to kamal setup my app by following this tutorial.

I set up 2 servers (one for the Ruby on Rails 7.1.2 app and one for the MySQL 8.0.31 database, both are Linux Ubuntu 23.10) and a NodeBalancer running on Linode.

My deploy.yml looks like this (I just changed sensitive references and removed comments):

service: my-app

image: myusername/my-app

servers:
  web:
    hosts:
      - 1.1.1.79

registry:
  username: myusername
  password:
    - KAMAL_REGISTRY_PASSWORD

env:
  clear:
    DB_HOST: 1.1.1.172
  secret:
    - RAILS_MASTER_KEY
    - MYSQL_ROOT_PASSWORD

accessories:
  db:
    image: mysql:8.0
    host: 1.1.1.172
    port: 3306
    env:
      clear:
        MYSQL_ROOT_HOST: '%'
      secret:
        - MYSQL_ROOT_PASSWORD
    files:
      # - config/mysql/production.cnf:/etc/mysql/my.cnf
      - db/production.sql:/docker-entrypoint-initdb.d/setup.sql
    directories:
      - data:/var/lib/mysql

My Dockerfile looks like this (sensitive references changed):

# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.2
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base

# Rails app lives here
WORKDIR /var/www/my-app.com/public

# Set production environment
ENV RAILS_ENV="production" \
    BUNDLE_DEPLOYMENT="1" \
    BUNDLE_PATH="/usr/local/bundle" \
    BUNDLE_WITHOUT="development"


# Throw-away build stage to reduce size of final image
FROM base as build_stage

# Install packages needed to build gems
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y build-essential git libmariadb-dev-compat libmariadb-dev default-libmysqlclient-dev libvips pkg-config

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
    rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
    bundle exec bootsnap precompile --gemfile

# Copy application code
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# We precompile assets locally. So, we disable assets precompile task.
## Precompiling assets for production without requiring secret RAILS_MASTER_KEY
#RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile


# Final stage for app image
FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build_stage /usr/local/bundle /usr/local/bundle
COPY --from=build_stage /var/www/my-app.com/public /var/www/my-app.com/public

# Run and own only the runtime files as a non-root user for security
RUN useradd rails --create-home --shell /bin/bash && \
    chown -R rails:rails db log storage tmp
USER rails:rails

# Entrypoint prepares the database.
ENTRYPOINT ["/var/www/my-app.com/public/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]

I also setup routes get 'up' => 'rails/health#show', :as => :rails_health_check, and many other things in app and on servers... please, ask for more info.

Now, I feel like I'm nearing the end of setup in seeing my app finally deployed.

When in the console I run kamal setup then I get:

$ kamal setup
  INFO [113abc39] Running /usr/bin/env mkdir -p .kamal on 1.1.1.79
  INFO [113abc39] Finished in 0.576 seconds with exit status 0 (successful).
Acquiring the deploy lock...
Ensure Docker is installed...
  INFO [23dc8290] Running docker -v on 1.1.1.79
  INFO [8ce41345] Running docker -v on 1.1.1.172
  INFO [23dc8290] Finished in 0.175 seconds with exit status 0 (successful).
  INFO [1b47e0ed] Running /usr/bin/env mkdir -p .kamal on 1.1.1.79
  INFO [1b47e0ed] Finished in 0.154 seconds with exit status 0 (successful).
  INFO [8ce41345] Finished in 0.630 seconds with exit status 0 (successful).
  INFO [fbc7dedc] Running /usr/bin/env mkdir -p .kamal on 1.1.1.172
  INFO [fbc7dedc] Finished in 0.156 seconds with exit status 0 (successful).
Push env files...
  INFO [167ead7f] Running /usr/bin/env mkdir -p .kamal/env/roles on 1.1.1.79
  INFO [167ead7f] Finished in 0.153 seconds with exit status 0 (successful).
  INFO Uploading .kamal/env/roles/my-app-web.env 100.0%
  INFO [07758eff] Running /usr/bin/env mkdir -p .kamal/env/traefik on 1.1.1.79
  INFO [07758eff] Finished in 0.149 seconds with exit status 0 (successful).
  INFO Uploading .kamal/env/traefik/traefik.env 100.0%
  INFO [6802051a] Running /usr/bin/env mkdir -p .kamal/env/accessories on 1.1.1.172
  INFO [6802051a] Finished in 0.088 seconds with exit status 0 (successful).
  INFO Uploading .kamal/env/accessories/my-app-db.env 100.0%
  INFO [0e6437f6] Running /usr/bin/env mkdir -p $PWD/my-app-db/data on 1.1.1.172
  INFO [0e6437f6] Finished in 0.153 seconds with exit status 0 (successful).
  INFO [100f3756] Running /usr/bin/env mkdir -p my-app-db/docker-entrypoint-initdb.d on 1.1.1.172
  INFO [100f3756] Finished in 0.154 seconds with exit status 0 (successful).
  INFO Uploading /Users/MyUser/Sites/my-app/db/production.sql 100.0%
  INFO [e795b56e] Running /usr/bin/env chmod 755 my-app-db/docker-entrypoint-initdb.d/setup.sql on 1.1.1.172
  INFO [e795b56e] Finished in 0.162 seconds with exit status 0 (successful).
  INFO [ef67d696] Running docker login -u [REDACTED] -p [REDACTED] on 1.1.1.172
  INFO [ef67d696] Finished in 1.091 seconds with exit status 0 (successful).
  INFO [79af1db2] Running docker run --name my-app-db --detach --restart unless-stopped --log-opt max-size="10m" --publish 3306:3306 --env-file .kamal/env/accessories/my-app-db.env --volume $PWD/my-app-db/docker-entrypoint-initdb.d/setup.sql:/docker-entrypoint-initdb.d/setup.sql --volume $PWD/my-app-db/data:/var/lib/mysql --label service="my-app-db" mysql:8.0 on 1.1.1.172
  INFO [79af1db2] Finished in 0.828 seconds with exit status 0 (successful).
Log into image registry...
  INFO [b13fcb2d] Running docker login -u [REDACTED] -p [REDACTED] as MyUser@localhost
  INFO [b13fcb2d] Finished in 1.744 seconds with exit status 0 (successful).
  INFO [89fdbda8] Running docker login -u [REDACTED] -p [REDACTED] on 1.1.1.79
  INFO [89fdbda8] Finished in 0.962 seconds with exit status 0 (successful).
Build and push app image...
  INFO [d7d4bf64] Running docker --version && docker buildx version as MyUser@localhost
  INFO [d7d4bf64] Finished in 0.228 seconds with exit status 0 (successful).
  INFO [d0df5bd3] Running docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-my-app-multiarch -t myusername/my-app:1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285 -t myusername/my-app:latest --label service="my-app" --file Dockerfile . as MyUser@localhost
 DEBUG [d0df5bd3] Command: docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-my-app-multiarch -t myusername/my-app:1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285 -t myusername/my-app:latest --label service="my-app" --file Dockerfile .
 DEBUG [d0df5bd3]   #0 building with "kamal-my-app-multiarch" instance using docker-container driver
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #1 [internal] load build definition from Dockerfile
 DEBUG [d0df5bd3]   #1 transferring dockerfile: 2.96kB done
 DEBUG [d0df5bd3]   #1 DONE 0.0s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #2 resolve image config for docker.io/docker/dockerfile:1
 DEBUG [d0df5bd3]   #2 ...
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #3 [auth] docker/dockerfile:pull token for registry-1.docker.io
 DEBUG [d0df5bd3]   #3 DONE 0.0s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #2 resolve image config for docker.io/docker/dockerfile:1
 DEBUG [d0df5bd3]   #2 DONE 1.3s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #4 docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021
 DEBUG [d0df5bd3]   #4 resolve docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021 done
 DEBUG [d0df5bd3]   #4 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #5 [linux/amd64 internal] load metadata for registry.docker.com/library/ruby:3.2.2-slim
 DEBUG [d0df5bd3]   #5 DONE 1.3s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #6 [linux/arm64 internal] load metadata for registry.docker.com/library/ruby:3.2.2-slim
 DEBUG [d0df5bd3]   #6 DONE 1.3s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #7 [internal] load .dockerignore
 DEBUG [d0df5bd3]   #7 transferring context: 782B done
 DEBUG [d0df5bd3]   #7 DONE 0.0s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #8 [linux/arm64 base 1/2] FROM registry.docker.com/library/ruby:3.2.2-slim@sha256:14eba677236d3360f2b66595c7fa0f2440ed6e33c519befe4d11c1242a8815a8
 DEBUG [d0df5bd3]   #8 resolve registry.docker.com/library/ruby:3.2.2-slim@sha256:14eba677236d3360f2b66595c7fa0f2440ed6e33c519befe4d11c1242a8815a8 done
 DEBUG [d0df5bd3]   #8 DONE 0.0s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #9 [linux/amd64 base 1/2] FROM registry.docker.com/library/ruby:3.2.2-slim@sha256:14eba677236d3360f2b66595c7fa0f2440ed6e33c519befe4d11c1242a8815a8
 DEBUG [d0df5bd3]   #9 resolve registry.docker.com/library/ruby:3.2.2-slim@sha256:14eba677236d3360f2b66595c7fa0f2440ed6e33c519befe4d11c1242a8815a8 done
 DEBUG [d0df5bd3]   #9 DONE 0.0s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #10 [internal] load build context
 DEBUG [d0df5bd3]   #10 transferring context: 3.31MB 0.2s done
 DEBUG [d0df5bd3]   #10 DONE 0.3s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #11 [linux/amd64 build_stage 2/5] COPY Gemfile Gemfile.lock ./
 DEBUG [d0df5bd3]   #11 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #12 [linux/amd64 base 2/2] WORKDIR /var/www/my-app.com/public
 DEBUG [d0df5bd3]   #12 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #13 [linux/amd64 build_stage 1/5] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y build-essential git libmariadb-dev-compat libmariadb-dev default-libmysqlclient-dev libvips pkg-config
 DEBUG [d0df5bd3]   #13 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #14 [linux/amd64 build_stage 3/5] RUN bundle install &&     rm -rf ~/.bundle/ "/usr/local/bundle"/ruby/*/cache "/usr/local/bundle"/ruby/*/bundler/gems/*/.git &&     bundle exec bootsnap precompile --gemfile
 DEBUG [d0df5bd3]   #14 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #15 [linux/arm64 build_stage 1/5] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y build-essential git libmariadb-dev-compat libmariadb-dev default-libmysqlclient-dev libvips pkg-config
 DEBUG [d0df5bd3]   #15 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #16 [linux/arm64 build_stage 2/5] COPY Gemfile Gemfile.lock ./
 DEBUG [d0df5bd3]   #16 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #17 [linux/arm64 base 2/2] WORKDIR /var/www/my-app.com/public
 DEBUG [d0df5bd3]   #17 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #18 [linux/arm64 build_stage 3/5] RUN bundle install &&     rm -rf ~/.bundle/ "/usr/local/bundle"/ruby/*/cache "/usr/local/bundle"/ruby/*/bundler/gems/*/.git &&     bundle exec bootsnap precompile --gemfile
 DEBUG [d0df5bd3]   #18 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #19 [linux/arm64 build_stage 4/5] COPY . .
 DEBUG [d0df5bd3]   #19 DONE 0.4s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #20 [linux/amd64 build_stage 4/5] COPY . .
 DEBUG [d0df5bd3]   #20 DONE 0.4s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #21 [linux/amd64 build_stage 5/5] RUN bundle exec bootsnap precompile app/ lib/
 DEBUG [d0df5bd3]   #21 ...
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #22 [linux/arm64 build_stage 5/5] RUN bundle exec bootsnap precompile app/ lib/
 DEBUG [d0df5bd3]   #22 DONE 0.4s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #21 [linux/amd64 build_stage 5/5] RUN bundle exec bootsnap precompile app/ lib/
 DEBUG [d0df5bd3]   #21 ...
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #23 [linux/arm64 stage-2 1/4] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y curl libsqlite3-0 libvips &&     rm -rf /var/lib/apt/lists /var/cache/apt/archives
 DEBUG [d0df5bd3]   #23 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #24 [linux/arm64 stage-2 2/4] COPY --from=build_stage /usr/local/bundle /usr/local/bundle
 DEBUG [d0df5bd3]   #24 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #25 [linux/arm64 stage-2 3/4] COPY --from=build_stage /var/www/my-app.com/public /var/www/my-app.com/public
 DEBUG [d0df5bd3]   #25 DONE 0.6s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #21 [linux/amd64 build_stage 5/5] RUN bundle exec bootsnap precompile app/ lib/
 DEBUG [d0df5bd3]   #21 DONE 3.6s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #26 [linux/arm64 stage-2 4/4] RUN useradd rails --create-home --shell /bin/bash &&     chown -R rails:rails db log storage tmp
 DEBUG [d0df5bd3]   #26 ...
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #27 [linux/amd64 stage-2 1/4] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y curl libsqlite3-0 libvips &&     rm -rf /var/lib/apt/lists /var/cache/apt/archives
 DEBUG [d0df5bd3]   #27 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #28 [linux/amd64 stage-2 2/4] COPY --from=build_stage /usr/local/bundle /usr/local/bundle
 DEBUG [d0df5bd3]   #28 CACHED
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #29 [linux/amd64 stage-2 3/4] COPY --from=build_stage /var/www/my-app.com/public /var/www/my-app.com/public
 DEBUG [d0df5bd3]   #29 DONE 0.9s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #26 [linux/arm64 stage-2 4/4] RUN useradd rails --create-home --shell /bin/bash &&     chown -R rails:rails db log storage tmp
 DEBUG [d0df5bd3]   #26 DONE 4.1s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #30 [linux/amd64 stage-2 4/4] RUN useradd rails --create-home --shell /bin/bash &&     chown -R rails:rails db log storage tmp
 DEBUG [d0df5bd3]   #30 DONE 2.8s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #31 exporting to image
 DEBUG [d0df5bd3]   #31 exporting layers
 DEBUG [d0df5bd3]   #31 exporting layers 2.1s done
 DEBUG [d0df5bd3]   #31 exporting manifest sha256:2189c7608c77c50b3d35dbee64f5f376522dd39606aaf0012c8d57be87bee6b5 done
 DEBUG [d0df5bd3]   #31 exporting config sha256:2864a102eb7a1bbb3344bac655ba7ccc7a9d5affd58d871e2a93c345661fbbac done
 DEBUG [d0df5bd3]   #31 exporting attestation manifest sha256:aa4681f6311223f61156d0627e70a3517cdd71ced8f5b9e06ac0872c0ee31ecc done
 DEBUG [d0df5bd3]   #31 exporting manifest sha256:f8f88ad52ffd1e826d52fc74d58da3e67f995ce724ce39ad560856036b5844b9 done
 DEBUG [d0df5bd3]   #31 exporting config sha256:fad286ba58ef9d3d91eb89e5f699c7522f104f043235401f8307ceba409a80a6 done
 DEBUG [d0df5bd3]   #31 exporting attestation manifest sha256:9a075bcfc897eb379da341ea9397221c24f888837db399ec2a5bf29e41fb76e1 done
 DEBUG [d0df5bd3]   #31 exporting manifest list sha256:c07f0f1527fa99cb7c3cd26de9c5b12937421e979952b608ae066179ef746ddb done
 DEBUG [d0df5bd3]   #31 pushing layers
 DEBUG [d0df5bd3]   #31 ...
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #32 [auth] myusername/my-app:pull,push token for registry-1.docker.io
 DEBUG [d0df5bd3]   #32 DONE 0.0s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   #31 exporting to image
 DEBUG [d0df5bd3]   #31 pushing layers 71.0s done
 DEBUG [d0df5bd3]   #31 pushing manifest for docker.io/myusername/my-app:1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285@sha256:c07f0f1527fa99cb7c3cd26de9c5b12937421e979952b608ae066179ef746ddb
 DEBUG [d0df5bd3]   #31 pushing manifest for docker.io/myusername/my-app:1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285@sha256:c07f0f1527fa99cb7c3cd26de9c5b12937421e979952b608ae066179ef746ddb 2.5s done
 DEBUG [d0df5bd3]   #31 pushing layers 2.2s done
 DEBUG [d0df5bd3]   #31 pushing manifest for docker.io/myusername/my-app:latest@sha256:c07f0f1527fa99cb7c3cd26de9c5b12937421e979952b608ae066179ef746ddb
 DEBUG [d0df5bd3]   #31 pushing manifest for docker.io/myusername/my-app:latest@sha256:c07f0f1527fa99cb7c3cd26de9c5b12937421e979952b608ae066179ef746ddb 1.3s done
 DEBUG [d0df5bd3]   #31 DONE 79.2s
 DEBUG [d0df5bd3]   
 DEBUG [d0df5bd3]   View build details: docker-desktop://dashboard/build/kamal-my-app-multiarch/kamal-my-app-multiarch0/bi4ia9ngc7sf2eu4nuj01q18u
  INFO [d0df5bd3] Finished in 91.171 seconds with exit status 0 (successful).
  INFO [51c3c4eb] Running docker image rm --force myusername/my-app:1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285 on 1.1.1.79
  INFO [51c3c4eb] Finished in 0.192 seconds with exit status 0 (successful).
  INFO [1857be3d] Running docker pull myusername/my-app:1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285 on 1.1.1.79
  INFO [1857be3d] Finished in 11.152 seconds with exit status 0 (successful).
  INFO [e848881f] Running docker inspect -f '{{ .Config.Labels.service }}' myusername/my-app:1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285 | grep -x my-app || (echo "Image myusername/my-app:1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285 is missing the `service` label" && exit 1) on 1.1.1.79
  INFO [e848881f] Finished in 0.185 seconds with exit status 0 (successful).
Ensure Traefik is running...
  INFO [b695fd6b] Running docker login -u [REDACTED] -p [REDACTED] on 1.1.1.79
  INFO [b695fd6b] Finished in 1.116 seconds with exit status 0 (successful).
  INFO [7afdf837] Running docker container start traefik || docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size="10m" --label traefik.http.routers.catchall.entryPoints="http" --label traefik.http.routers.catchall.rule="PathPrefix(\`/\`)" --label traefik.http.routers.catchall.service="unavailable" --label traefik.http.routers.catchall.priority="1" --label traefik.http.services.unavailable.loadbalancer.server.port="0" traefik:v2.9 --providers.docker --log.level="DEBUG" on 1.1.1.79
  INFO [7afdf837] Finished in 0.928 seconds with exit status 0 (successful).
Ensure app can pass healthcheck...
  INFO [847c8b12] Running docker run --detach --name healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285 --publish 3999:3000 --label service=healthcheck-my-app -e KAMAL_CONTAINER_NAME="healthcheck-my-app" --env-file .kamal/env/roles/my-app-web.env --health-cmd "curl -f http://localhost:3000/up || exit 1" --health-interval "1s" myusername/my-app:1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285 on 1.1.1.79
  INFO [847c8b12] Finished in 0.990 seconds with exit status 0 (successful).
  INFO [611f0382] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 1.1.1.79
  INFO [611f0382] Finished in 0.310 seconds with exit status 0 (successful).
  INFO container not ready (starting), retrying in 1s (attempt 1/7)...
  INFO [0f73740a] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 1.1.1.79
  INFO [0f73740a] Finished in 0.213 seconds with exit status 0 (successful).
  INFO container not ready (starting), retrying in 2s (attempt 2/7)...
  INFO [cf876375] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 1.1.1.79
  INFO [cf876375] Finished in 0.150 seconds with exit status 0 (successful).
  INFO container not ready (unhealthy), retrying in 3s (attempt 3/7)...
  INFO [05982682] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 1.1.1.79
  INFO [05982682] Finished in 0.146 seconds with exit status 0 (successful).
  INFO container not ready (unhealthy), retrying in 4s (attempt 4/7)...
  INFO [d152421d] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 1.1.1.79
  INFO [d152421d] Finished in 0.179 seconds with exit status 0 (successful).
  INFO container not ready (unhealthy), retrying in 5s (attempt 5/7)...
  INFO [b206d097] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 1.1.1.79
  INFO [b206d097] Finished in 0.149 seconds with exit status 0 (successful).
  INFO container not ready (unhealthy), retrying in 6s (attempt 6/7)...
  INFO [de81913a] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 1.1.1.79
  INFO [de81913a] Finished in 0.160 seconds with exit status 0 (successful).
  INFO container not ready (unhealthy), retrying in 7s (attempt 7/7)...
  INFO [7930668d] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 1.1.1.79
  INFO [7930668d] Finished in 0.147 seconds with exit status 0 (successful).
  INFO [10021bce] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker logs --tail 50 2>&1 on 1.1.1.79
  INFO [10021bce] Finished in 0.250 seconds with exit status 0 (successful).
 ERROR bin/rails aborted!
LoadError: libmariadb.so.3: cannot open shared object file: No such file or directory - /usr/local/bundle/ruby/3.2.0/gems/mysql2-0.5.5/lib/mysql2/mysql2.so (LoadError)
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/bundle/ruby/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
/usr/local/bundle/ruby/3.2.0/gems/mysql2-0.5.5/lib/mysql2.rb:36:in `<main>'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/bundle/ruby/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
/var/www/my-app.com/public/config/application.rb:7:in `<main>'
/var/www/my-app.com/public/Rakefile:4:in `require_relative'
/var/www/my-app.com/public/Rakefile:4:in `<main>'
/usr/local/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:43:in `block in with_rake'
/usr/local/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:41:in `with_rake'
/usr/local/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:156:in `invoke_rake'
/usr/local/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:73:in `block in invoke'
/usr/local/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:149:in `with_argv'
/usr/local/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:69:in `invoke'
/usr/local/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/commands.rb:18:in `<main>'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
./bin/rails:4:in `<main>'
(See full trace by running task with --trace)
 ERROR {
  "Status": "unhealthy",
  "FailingStreak": 2,
  "Log": [
    {
      "Start": "2023-12-16T22:06:30.737462655+01:00",
      "End": "2023-12-16T22:06:30.966660307+01:00",
      "ExitCode": 1,
      "Output": "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\ncurl: (7) Failed to connect to localhost port 3000 after 14 ms: Couldn't connect to server\n"
    },
    {
      "Start": "2023-12-16T22:06:31.975366539+01:00",
      "End": "2023-12-16T22:06:32.198491049+01:00",
      "ExitCode": 1,
      "Output": "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\ncurl: (7) Failed to connect to localhost port 3000 after 9 ms: Couldn't connect to server\n"
    }
  ]
}
  INFO [1895c459] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker stop on 1.1.1.79
  INFO [1895c459] Finished in 0.212 seconds with exit status 0 (successful).
  INFO [501e14ae] Running docker container ls --all --filter name=^healthcheck-my-app-1752e623352cc3fb35bd1679d45bbc98194f017d_uncommitted_9c902faf2c966285$ --quiet | xargs docker container rm on 1.1.1.79
  INFO [501e14ae] Finished in 0.239 seconds with exit status 0 (successful).
  Finished all in 139.3 seconds
Releasing the deploy lock...
  Finished all in 145.7 seconds
  ERROR (Kamal::Cli::Healthcheck::Poller::HealthcheckError): Exception while executing on host 1.1.1.79: container not ready (unhealthy)

I don't understand well the problem: is it related to Traefik or MySQL? Where should I look for solving the problem?

1

There are 1 answers

1
user502052 On BEST ANSWER

MySQL is being installed in the build stage. I need to install it above that stage. Here is an updated Dockerfile.

Thanks to guy @acidtib from group Kamal on Discord.