shopware / production

Shopware 6 production template
https://shopware.com
177 stars 152 forks source link

Shopware Docker #62

Closed denis-ev closed 4 years ago

denis-ev commented 4 years ago

Is there a timeframe when the docker image is not experimental anymore? I've been trying to set shop ware via docker up and I can get to the login screen but even when creating a new user via the cli I just cannot login.

Something went wrong requesting "".

Shopware is supposed to run behind Traefik, but when deleting all the data and retrying the setup via the web installation wizard I get to put in admin user etc, and then there is an error showing. The Error says

Slim Application Error
The application could not run because of the following error:

Details

Type: Shopware\Recovery\Common\HttpClient\ClientException
Code: 7
Message: Failed to connect to changedwebsite.com port 80: Connection refused
File: /sw6/vendor/shopware/recovery/Common/src/HttpClient/CurlClient.php
Line: 97
Trace

#0 /sw6/vendor/shopware/recovery/Common/src/HttpClient/CurlClient.php(35): Shopware\Recovery\Common\HttpClient\CurlClient->call('http://dev.dogg...', 'POST', Array, '{"grant_type":"...')
#1 /sw6/vendor/shopware/recovery/Install/src/app.php(514): Shopware\Recovery\Common\HttpClient\CurlClient->post('http://dev.dogg...', '{"grant_type":"...', Array)
#2 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#3 /sw6/vendor/shopware/recovery/Common/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(40): call_user_func(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#4 /sw6/vendor/shopware/recovery/Common/vendor/slim/slim/Slim/Route.php(281): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#5 /sw6/vendor/shopware/recovery/Common/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#6 /sw6/vendor/shopware/recovery/Common/vendor/slim/slim/Slim/Route.php(268): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#7 /sw6/vendor/shopware/recovery/Common/vendor/slim/slim/Slim/App.php(503): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))
#8 /sw6/vendor/shopware/recovery/Install/src/app.php(158): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#9 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#10 /sw6/vendor/shopware/recovery/Common/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#11 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#12 /sw6/vendor/shopware/recovery/Common/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#13 /sw6/vendor/shopware/recovery/Common/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#14 /sw6/vendor/shopware/recovery/Common/vendor/slim/slim/Slim/App.php(392): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#15 /sw6/vendor/shopware/recovery/Common/vendor/slim/slim/Slim/App.php(297): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#16 /sw6/vendor/shopware/recovery/Install/index.php(51): Slim\App->run()
#17 /sw6/public/recovery/install/index.php(6): require_once('/sw6/vendor/sho...')
#18 {main}
shyim commented 4 years ago

You need an extra_hosts with your domain to 127.0.0.1. The Installer tries to communicate with himself

denis-ev commented 4 years ago

@shyim thanks for the fast response, I have

extra_hosts:
      - "changedwebsite.com:127.0.0.1"

in the docker-compose file.

this is how the whole file looks like

#override defaults for dev
version: "3.7"

networks:
  proxy_traefik:
    external:
      name: traefik_traefik
  shopware6:

services:
  app:
    image: shopware-production:local
    build: ./data
    depends_on:
      - mysql
      - elasticsearch
    networks:
      - "proxy_traefik"
      - "shopware6"
    #ports:
    #  - 8000:8000
    #  - 8005:8000
    extra_hosts:
      - "changedwebsite.com:127.0.0.1"
    environment:
      - APP_ENV=dev
      - APP_SECRET=appsecret
      - APP_URL=https://changedwebsite.com
      #- TRUSTED_PROXIES=127.0.0.1,127.0.0.2
      #- TRUSTED_HOSTS=localhost,example.com
      - MAILER_URL=null://localhost
      - DATABASE_URL=mysql://shopware:mysqlpassword@changedwebsite_mysql_1:3306/shopware
      - COMPOSER_HOME=/sw6/var/cache/composer
      - INSTANCE_ID=instanceid
      - BLUE_GREEN_DEPLOYMENT=1
      - SHOPWARE_HTTP_CACHE_ENABLED=1
      - SHOPWARE_HTTP_DEFAULT_TTL=7200
      - SHOPWARE_ES_ENABLED=0
      - SHOPWARE_ES_INDEXING_ENABLED=0
      - SHOPWARE_ES_INDEX_PREFIX=sw
      - SHOPWARE_CDN_STRATEGY_DEFAULT=id
    volumes:
      - "./data/config/jwt:/sw6/config/jwt"
      - "./data/public/bundles:/sw6/public/bundles"
      - "./data/public/media:/sw6/public/media"
      - "./data/public/sitemap:/sw6/public/sitemap"
      - "./data/public/theme:/sw6/public/theme"
      - "./data/public/thumbnail:/sw6/public/thumbnail"
      - "./data/var:/sw6/var"
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik_traefik"
      - "traefik.http.services.changedwebsite.loadbalancer.server.scheme=http"
      - "traefik.http.services.changedwebsite.loadbalancer.server.port=8000"
      - "traefik.http.routers.changedwebsite-http.rule=Host(`changedwebsite.com`)"
      - "traefik.http.routers.changedwebsite-http.entrypoints=http"
      - "traefik.http.routers.changedwebsite-http.middlewares=redirect@file"
      - "traefik.http.routers.changedwebsite.rule=Host(`changedwebsite.com`)"
      - "traefik.http.routers.changedwebsite.entrypoints=https"
      - "traefik.http.routers.changedwebsite.tls=true"
      - "traefik.http.routers.changedwebsite.tls.domains[0].main=changedwebsite.com"
      - "traefik.http.routers.changedwebsite.tls.certresolver=dns"

  mysql:
    image: mysql:5.7
    hostname: mysql
    networks:
      - "shopware6"
    environment:
      - MYSQL_ROOT_PASSWORD= mysqlrootpassword
      - MYSQL_DATABASE=shopware
      - MYSQL_USER=shopware
      - MYSQL_PASSWORD=mysqlpassword
    volumes:
      - "./mysql-data:/var/lib/mysql"

  elasticsearch:
    image: elastic/elasticsearch:7.1.1
    networks:
      - "shopware6"
    environment:
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.type=single-node
shyim commented 4 years ago

Strange. But anyway this problem should not effect the shop. You can login using /admin into the shop

denis-ev commented 4 years ago

I can access /admin, but then I cannot login.

This is the error I get ... Something went wrong requesting "".

soebbing commented 4 years ago

Can you access the recovery url? Maybe the installation hasn't completed yet

denis-ev commented 4 years ago

@soebbing changedwebsite.com/recovery forwards to http://changedwebsite.com:8000/recovery/ which won't work because it's behind a proxy

Edit: when I remove the port part, I get NGINX 403 forbidden

https://changedwebsite.com/recovery/install/ shows this

Der Installer wurde bereits ausgeführt.

Wenn Sie den Installationsvorgang erneut ausführen möchten, löschen Sie die Datei install.lock!

The installation process has already been finished.

If you want to run the installation process again, delete the file install.lock!
denis-ev commented 4 years ago

I've tested some more and found this. XMLHttpRequest cannot load http://dev.doggo.kaufen/api/oauth/token due to access control checks.

denis-ev commented 4 years ago

@shyim @soebbing The problem was that I did not set up the trusted proxy, after that I can finally login. Thank you for the help and ideas.

sawden commented 3 years ago

@denis-ev

Would you share your traefik/shopware configuration? I have difficulties setting up shopware with docker-compose. I am currently getting a "Gateway Timeout"...

You would help me very much! :)

denis-ev commented 3 years ago

@sawden

Would you share your traefik/shopware configuration? I have difficulties setting up shopware with docker-compose. I am currently getting a "Gateway Timeout"...

You would help me very much! :)

docker-compose.yml

version: '3'

networks:
  proxy_traefik:
    external:
      name: traefik_traefik
  default:

services:
  # Load Balancer / SSL / Web Server
  placeholder:
    image: webdevops/php-nginx:7.3
    restart: unless-stopped
    depends_on:
      - db
    networks:
      -  proxy_traefik
      -  default
    volumes:
      - ./web:/app
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik_traefik"
      - "traefik.http.services.placeholder.loadbalancer.server.scheme=http"
      - "traefik.http.services.placeholder.loadbalancer.server.port=80"
      - "traefik.http.routers.placeholder-http.rule=Host(`placeholder`)"
      - "traefik.http.routers.placeholder-http.entrypoints=http"
      - "traefik.http.routers.placeholder-http.middlewares=redirect@file"
      - "traefik.http.routers.placeholder.rule=Host(`placeholder `)"
      - "traefik.http.routers.placeholder.entrypoints=https"
      - "traefik.http.routers.placeholder.middlewares=doggode"
      - "traefik.http.routers.placeholder.tls=true"
      - "traefik.http.routers.placeholder.tls.domains[0].main=placeholder"
      - "traefik.http.routers.placeholder.tls.domains[0].sans=*.placeholder"
      - "traefik.http.routers.placeholder.tls.certresolver=dns"
    environment:
      VIRTUAL_HOST: placeholder
      VIRTUAL_PORT: 80
      WEB_DOCUMENT_INDEX: shopware.php

  db:
    image: mariadb
    command: mysqld --sql_mode=""
    container_name: db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: "randompassword"
      MYSQL_DATABASE: "databasename"
      MYSQL_USER: "shop"
      MYSQL_PASSWORD: "randompassword"
      TZ: "Europe/Berlin"
    volumes:
      - ./mysql:/var/lib/mysql
      - ./dump_new.sql:/docker-entrypoint-initdb.d/dump.sql
    networks:
      - default
  ftp:
    image: stilliard/pure-ftpd:hardened
    restart: unless-stopped
    environment:
      - PUBLICHOST={{public ip}}
      - FTP_USER_NAME=randomname
      - FTP_USER_PASS=randompassword
      - FTP_USER_HOME=/var/www/html
      - FTP_USER_UID=1000
      - FTP_USER_GID=1000
    ports:
      # active ftp
      - "21:21"

      # passive ftp ports, may differ if you configured them differently
      - "30000-30009:30000-30009"
    volumes:
      - ./web:/var/www/html

traefik docker-compose.yml

version: '3'

networks:
  traefik:
    driver: bridge

services:
  # Load Balancer / SSL / Web Server
  traefik:
    image: traefik:v2.3.1
    restart: unless-stopped
    networks:
      traefik:
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /root/docker/traefik/traefik.yaml:/traefik.yaml
      - /root/docker/traefik/acme.json:/acme.json
      - /root/docker/traefik/conf.d/:/conf.d/
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik_traefik"
      - "traefik.http.routers.traefik-http.rule=Host(`placeholder`)"
      - "traefik.http.routers.traefik-http.entrypoints=http"
      - "traefik.http.routers.traefik-http.middlewares=redirect@file"
      - "traefik.http.routers.traefik.rule=Host(`placeholder`)"
      - "traefik.http.routers.traefik.entrypoints=https"
      - "traefik.http.routers.traefik.middlewares=basicAuth@file"
      - "traefik.http.routers.traefik.tls=true"
      - "traefik.http.routers.traefik.tls.domains[0].main=placeholder"
      - "traefik.http.routers.traefik.tls.domains[0].sans=*.placeholder"
      - "traefik.http.routers.traefik.tls.certresolver=dns"
      - "traefik.http.routers.traefik.service=api@internal"
    environment:
      - CF_API_EMAIL=CLOUDFLAREEMAIL
      - CF_API_KEY=PRIVATEKEYPLACEHOLDER

This is how I got it working, haven't had much time to improve it yet tho.

denis-ev commented 3 years ago

@sawden and in your shopware config.php the trusted proxies should be added ...

<?php

$_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';

return [
  'db' => [
    'host' => 'db',
    'port' => '3306',
    'username' => 'randomname',
    'password' => 'randompassword',
    'dbname' => 'randomdbname',
  ],
  'trustedproxies' => [
    '127.0.0.1',
    '192.168.16.1' # depends on the ip of your traefik
  ],
];
sawden commented 3 years ago

@denis-ev You are the best! I've adjusted my configuration but I always get a 500 error at the end.

Since there is no documentary, this is how I proceeded:

  1. Create a docker-compose.yml
    
    version: '3'

networks: traefik: external: true example_shopware: services: example-shopware: image: webdevops/php-nginx:7.3 restart: unless-stopped depends_on:

COMPOSER_HOME=/tmp/composer

BLUE_GREEN_DEPLOYMENT=1

SHOPWARE_ES_HOSTS= SHOPWARE_ES_ENABLED=0 SHOPWARE_ES_INDEXING_ENABLED=0 SHOPWARE_ES_INDEX_PREFIX= SHOPWARE_HTTP_CACHE_ENABLED=1 SHOPWARE_HTTP_DEFAULT_TTL=7200

INSTALL_LOCALE=de-DE


4. Run docker-compose up -d
5. Start the bash inside my "example-shopware_1" container and run `composer install` and `bin / console system: install --create-database --basic-setup`
6. Run ` chmod 0777 /app/var/*` because shopware can't create log files.
7. Load the page and get a "The server returned a "500 Internal Server Error".

Have I forgotten something? Maybe you have a helpful hint because otherwise I've got no more ideas.
Our traefik configs the same btw. :)!