Clivern / Lynx

🐺 A Fast, Secure and Reliable Terraform Backend, Set up in Minutes.
https://lynx.clivern.com/
MIT License
210 stars 5 forks source link

Docker Compose: Module Lynx.Repo.Migrations.CreateConfigs is already compiled #67

Open uvulpos opened 1 month ago

uvulpos commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

Development or production environment

Additional context


user@computer Terraform-Lynx % docker compose up --abort-on-container-exit
[+] Running 7/7
 ✔ app 6 layers [⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                                            14.8s 
   ✔ 70ba6f391a98 Already exists                                                                                            0.0s 
   ✔ 03253c46bc5e Pull complete                                                                                             9.5s 
   ✔ 70b3bbd10c18 Pull complete                                                                                             0.7s 
   ✔ 40eef8e53e37 Pull complete                                                                                             1.4s 
   ✔ 5d19a66e937c Pull complete                                                                                             4.8s 
   ✔ 2974444833c0 Pull complete                                                                                             4.2s 
[+] Running 4/3
 ✔ Container terraform-lynx-nginx-1                                                                                                                   Created0.5s     Created                                                                                0.0s 
 ✔ Container terraform-lynx-db-1                                                                                                                      Created0.0s 
 ✔ Container terraform-lynx-app-1                                                                                                                     Recreated0.5s 
 ! app The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested 0.0s 
Attaching to app-1, db-1, nginx-1
db-1     | 
db-1     | PostgreSQL Database directory appears to contain a database; Skipping initialization
db-1     | 
nginx-1  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx-1  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx-1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
db-1     | 2024-05-26 21:53:28.541 UTC [1] LOG:  starting PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
db-1     | 2024-05-26 21:53:28.541 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db-1     | 2024-05-26 21:53:28.541 UTC [1] LOG:  listening on IPv6 address "::", port 5432
nginx-1  | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
db-1     | 2024-05-26 21:53:28.552 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
nginx-1  | 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
nginx-1  | /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
db-1     | 2024-05-26 21:53:28.573 UTC [29] LOG:  database system was shut down at 2024-05-26 21:52:58 UTC
nginx-1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx-1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx-1  | /docker-entrypoint.sh: Configuration complete; ready for start up
db-1     | 2024-05-26 21:53:28.583 UTC [1] LOG:  database system is ready to accept connections
app-1    | ** (ArgumentError) could not call Module.put_attribute/3 because the module Lynx.Repo.Migrations.CreateConfigs is already compiled
app-1    |     (elixir 1.16.1) lib/module.ex:2360: Module.assert_not_readonly!/2
app-1    |     (elixir 1.16.1) lib/module.ex:2041: Module.__put_attribute__/5
app-1    |     /app/lib/lynx-0.11.7/priv/repo/migrations/20230304233120_create_users.exs:6: (module)
app-1 exited with code 1
Aborting on container exit...
[+] Stopping 3/3
 ✔ Container terraform-lynx-nginx-1  Stopped                                                                                0.2s 
 ✔ Container terraform-lynx-app-1    Stopped                                                                                0.0s 
 ✔ Container terraform-lynx-db-1     Stopped                                                                                0.1s 
Clivern commented 1 month ago

Hi @uvulpos,

I think the issue is the docker container image built for a different CPU architecture than your host machine. I bet you're using mac M1.

I think you need to set DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose up -d to force docker to use linux/amd64.

or build the image for your platform (needs testing since i believe there might be issues https://elixirforum.com/t/cant-compile-elixir-phoenix-api-in-docker-build-step/56863/4)

$ git clone https://github.com/Clivern/Lynx.git
$ docker build --platform linux/arm64 -t clivern/lynx:0.11.9 .

I've done a quick check and things seems for a linux server.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 23.10
Release:    23.10
Codename:   mantic

$ apt-get update
$ apt-get upgrade -y

$ apt-get install docker.io docker-compose -y

$ mkdir /opt/app
$ cd /opt/app

$ wget https://raw.githubusercontent.com/Clivern/Lynx/main/docker-compose.yml
$ wget https://raw.githubusercontent.com/Clivern/Lynx/main/nginx.conf

$ docker-compose up -d
Creating network "app_default" with the default driver
Creating volume "app_db" with local driver
Creating volume "app_app" with local driver
Pulling db (postgres:16.3)...
16.3: Pulling from library/postgres
09f376ebb190: Pull complete
119215dfb3e3: Pull complete
e02bbc8c8252: Pull complete
061f31803c55: Pull complete
accd4903f49a: Pull complete
2016ff8e6e3a: Pull complete
088e651df7e9: Pull complete
ed155773e5e0: Pull complete
ffebb35d2904: Pull complete
293f0bec643a: Pull complete
1655a257a5b5: Pull complete
4ddba458499d: Pull complete
90e48ae03559: Pull complete
822c1a513e6a: Pull complete
Digest: sha256:1bf73ccae25238fa555100080042f0b2f9be08eb757e200fe6afc1fc413a1b3c
Status: Downloaded newer image for postgres:16.3
Pulling app (clivern/lynx:0.11.9)...
0.11.9: Pulling from clivern/lynx
70ba6f391a98: Pull complete
504f7dc7092a: Pull complete
b306aaae915c: Pull complete
9792344edb52: Pull complete
6258826cb2cc: Pull complete
9161726506e5: Pull complete
Digest: sha256:42fb8ad273d2e2eb09961fdfd4b9cfca00aea59a4a6877a2682537f3308087cc
Status: Downloaded newer image for clivern/lynx:0.11.9
Pulling nginx (nginx:1.25.4-alpine3.18)...
1.25.4-alpine3.18: Pulling from library/nginx
619be1103602: Pull complete
ed3e62e73b33: Pull complete
5126dce06df7: Pull complete
1d0dd2dc2265: Pull complete
2b1ab92f0231: Pull complete
6eba808ac059: Pull complete
57038e85fbb8: Pull complete
eec94c9845c0: Pull complete
Digest: sha256:31bad00311cb5eeb8a6648beadcf67277a175da89989f14727420a80e2e76742
Status: Downloaded newer image for nginx:1.25.4-alpine3.18
Creating app_db_1    ... done
Creating app_nginx_1 ... done
Creating app_app_1   ... done

$ curl http://127.0.0.1/_health -s | jq .
{
  "status": "ok"
}

// Install manually 

$ curl http://127.0.0.1/_ready -s | jq .
{
  "status": "ok"
}
Clivern commented 1 month ago

I tried to add linux/arm64 to the pipeline and see if it works but sound like Dockerfile need some changes to support arm64 arch build. Marking the ticket as enhancement

name: Publish Docker Image

on:
  release:
    types: [published]

jobs:
  push_to_registry:
    name: Push Docker image to Docker Hub
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v4

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@f7b4ed12385588c3f9bc252f0a2b520d83b52d48
        with:
          images: clivern/lynx

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          platforms: linux/amd64,linux/arm64
          file: ./Dockerfile
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
uvulpos commented 1 month ago

I would add the todo to verify, if this dockerfile even does at least some caching. When ground breaking stuff as the base image can be variable idk if the buildx cache is even working. But that's just an assumption