1

I used docker-compose for setting on my local machine.

Vapor app is working fine without using docker.

Environment

  • MacBook M1 Pro 14inch 2021
  • 32GB Ram

But I got an error at Step 3 (Step 1, and 2 are ok, Swift compiler builds Vapor app successfully)

Received signal 4. Backtrace:

enter image description here

#!/bin/bash
echo "Step 1: Build Docker"
docker-compose -f local-docker-compose.yml build
echo "Step 2: Start dependencies"
docker-compose -f local-docker-compose.yml run --rm
echo "Step 3: Start Vapor App"
docker-compose -f local-docker-compose.yml up myapp-beta
# Build image
FROM --platform=linux/x86-64 swift:5.5-focal as build

RUN apt-get update -y \
    && apt-get install -y libsqlite3-dev

WORKDIR /build

COPY . .

RUN swift build \
    --enable-test-discovery \
    -c release \
    -Xswiftc -g


# Run image
FROM --platform=linux/x86-64 swift:5.5-focal-slim

RUN useradd --user-group --create-home --home-dir /app vapor

WORKDIR /app

COPY --from=build --chown=vapor:vapor /build/.build/release /app
COPY --from=build --chown=vapor:vapor /build/Public /app/Public

# ARS RDS Environment ARG
ARG AWS_RDS_HOST
ARG AWS_RDS_PORT
ARG AWS_RDS_USER
ARG AWS_RDS_PASS
ARG AWS_RDS_DB

# SignInWithApple Environment ARG
ARG SIWA_ID
ARG SIWA_REDIRECT_URL
ARG SIWA_JWK_ID
ARG SIWA_PRIVATE_KEY
ARG SIWA_TEAM_ID
ARG SIWA_APP_BUNDLE_ID

# Set Environment
RUN echo "SIWA_ID=${SIWA_ID}" > .env.testing
RUN echo "SIWA_REDIRECT_URL=${SIWA_REDIRECT_URL}" >> .env.testing
RUN echo "SIWA_JWK_ID=${SIWA_JWK_ID}" >> .env.testing
RUN echo "SIWA_PRIVATE_KEY=${SIWA_PRIVATE_KEY}" >> .env.testing
RUN echo "SIWA_TEAM_ID=${SIWA_TEAM_ID}" >> .env.testing
RUN echo "SIWA_APP_BUNDLE_ID=${SIWA_APP_BUNDLE_ID}" >> .env.testing

RUN echo "DB_HOST=${AWS_RDS_HOST}" >> .env.testing
RUN echo "DB_PORT=${AWS_RDS_PORT}" >> .env.testing
RUN echo "DB_USER=${AWS_RDS_USER}" >> .env.testing
RUN echo "DB_PASS=${AWS_RDS_PASS}" >> .env.testing
RUN echo "DB_NAME=${AWS_RDS_DB}" >> .env.testing

USER vapor

EXPOSE 8080

ENTRYPOINT ["./Run"]
CMD ["serve", "--env", "local", "--hostname", "0.0.0.0", "--port", "8080"]

version: '3.7'
services:
  myapp-beta:
    depends_on:
      - postgres
    build:
      context: .
      args:
        AWS_RDS_HOST: postgres
        AWS_RDS_PORT: 5432
        AWS_RDS_USER: test
        AWS_RDS_PASS: test1228!1
        AWS_RDS_DB: myapp_db
        SIWA_ID: com.beta.myapp.service
        SIWA_REDIRECT_URL: localhost:8080
        SIWA_JWK_ID: JLJKLXXXX
        SIWA_PRIVATE_KEY: xxxxxxx
        SIWA_TEAM_ID: 9DFSXXXX
        SIWA_APP_BUNDLE_ID: com.beta.myapp
      dockerfile: local.Dockerfile
    ports:
      - '8080:8080'

  postgres:
    image: postgres
    environment:
      POSTGRES_USER: test
      POSTGRES_PASSWORD: test1228!1
      POSTGRES_DB: myapp_db

  start_dependencies:
    image: dadarek/wait-for-dependencies
    depends_on:
      - postgres
    command: postgres:5432

Shawn Baek
  • 1,928
  • 3
  • 20
  • 34
  • What's the error above? You might need to set the platform in Docker Compose. (Additionally cross compiling is not always guaranteed to work and if you're running locally any not just run as ARM?) – 0xTim Aug 15 '22 at 12:56
  • @0xTim I got an SwiftBackTraceError message. Yes It runs on ARM (My MacBook is M1 Pro model) – Shawn Baek Aug 17 '22 at 17:58
  • https://github.com/vapor/vapor/issues/2777 – Shawn Baek Aug 17 '22 at 17:59
  • Is there anything in the logs? Unfortunately backtrace doesn't work too well on ARM so it might be masking the error – 0xTim Aug 18 '22 at 08:59

1 Answers1

1

focal now includes arm64 arch that is necessary to run on M1. Here is the manifest:

docker manifest inspect swift:5.6-focal
{
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
   "manifests": [
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 1162,
         "digest": "sha256:a34fb87d14544c49d5aa30c90fcf18347d301e7db1b1e917b23796d687c3e178",
         "platform": {
            "architecture": "amd64",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 1162,
         "digest": "sha256:3708d167c44e62c928356c1aac9ba27ab77c7a4970d32dc8126a58ca5e2c0520",
         "platform": {
            "architecture": "arm64",
            "os": "linux",
            "variant": "v8"
         }
      }
   ]
}

You Dockerfile just needs to start with:

FROM swift:focal
cora
  • 1,916
  • 1
  • 10
  • 18