Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traefik configuration - Investigating #112

Open
LiamKarlMitchell opened this issue Jun 11, 2020 · 0 comments
Open

Traefik configuration - Investigating #112

LiamKarlMitchell opened this issue Jun 11, 2020 · 0 comments

Comments

@LiamKarlMitchell
Copy link

LiamKarlMitchell commented Jun 11, 2020

Goal: To have this docker run on my existing Traefik/docker which runs on WSL 2 - Ubuntu on WIndows 10

Traefik video talk here: https://youtu.be/RP40Iv_0yvA

Extra goals: See about proxying services such as phpmyadmin, xdebug, live reload, database through these domains.

Rather than forwarding a port Traefik lets you reverse proxy a domain and ports with TLS/certs (optional) to docker containers for example.

Attempting to set this up with Traefik and a magento2.local domain for development of extensions/themes locally.

Assumption Traefik already configured, I'll see about documenting this later.
Assumption Docker WSL 2 Ubuntu Windows 10 build 2004 > already set up.

Add 127.0.0.1 magento2.local to windows host file.

ubuntu
curl -s https://raw.githubusercontent.com/clean-docker/Magento2/master/init | bash -s MYMAGENTO2 clone

Edit the docker-compose.yml to change network and add labels as per below.

Install this to speed up docker compose installs and nano to edit install-magento2 script.

docker-compose exec apache bash
composer global require hirak/prestissimo
apt-get install nano

nano /usr/local/bin/install-magento2
Change domain from localhost to magento2.local.
Change other settings as you wish e.g. timezone.
Save and Exit nano.

exit that shell.

cd MYMAGENTO2
docker-compose up -d
./shell
rm index.php
install-magento2

Supply repo.magento.com username/pass keys.
These are from
https://marketplace.magento.com/customer/accessKeys/

Answer yes to save details to auth.json?
Y

Getting a lot of cannot create cache directory warnings with a few yellow background I'll assume that it is normal.

Setup is stuck here for now...

image

Going to leave it running to see if it works, maybe it is just going to take a few hours or something.

docker-compose.yml with Traefik settings applied.

version: '2'
services:
  apache:
    image: rafaelcgstz/magento2
    # build: .
#    ports:
#      - "80:80" # web
#      - "9001:9000" # xdebug
      # - "35729:35729" # live reload
    volumes:
      - ./src:/var/www/html
      - ~/.composer:/var/www/.composer
      - ~/.npm:/var/www/.npm
      # - ~/.nvm:/var/www/.nvm
    environment:
      XDEBUG_CONFIG: "remote_host=localhost"
      PHP_IDE_CONFIG: "serverName=Docker"
    depends_on:
      - db
    links:
      - db
    labels:
        - "traefik.enable=true"
        - "traefik.docker.network=web"
        # https
        - "traefik.http.routers.magento2.rule=Host(`magento2.local`)"
        - "traefik.http.routers.magento2.service=magento2"
        - "traefik.http.services.magento2.loadbalancer.server.port=80"
        # http
        - "traefik.http.routers.magento2-http.entrypoints=http"
        - "traefik.http.middlewares.magento2-http.redirectscheme.scheme=https"
        - "traefik.http.routers.magento2-http.rule=Host(`magento2.local`)"
        - "traefik.http.routers.magento2-http.service=magento2"
        # https
        - "traefik.http.routers.magento2.entrypoints=https"
        - "traefik.http.routers.magento2.tls=true"
        - "traefik.http.routers.magento2.tls.certresolver=http"
        # TODO: Find how to configure http and https with http redirect on same service name?
        
          # # TODO: Find how to configure http and https with http redirect on same service name?
          # # xdebug
          # - "traefik.tcp.routers.xdebug.rule=HostSNI(`*`)"
          # - "traefik.tcp.routers.xdebug.entrypoints=xdebug"
          # - "traefik.tcp.routers.xdebug.service=xdebug-svc"
          # - "traefik.tcp.services.xdebug-svc.loadbalancer.server.port=9000"
          # # live reload
          # - "traefik.tcp.routers.livereload.rule=HostSNI(`*`)"
          # - "traefik.tcp.routers.livereload.entrypoints=livereload"
          # - "traefik.tcp.routers.livereload.service=livereload-svc"
          # - "traefik.tcp.services.livereload-svc.loadbalancer.server.port=35729"
    networks:
      - web

  db:
    image: mariadb
#    ports:
#     - 3300:3306
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=magento
      - MYSQL_USER=magento
      - MYSQL_PASSWORD=magento
    volumes:
      - dbdata:/var/lib/mysql
    labels:
      - "traefik.enable=true"
      - "traefik.tcp.routers.mariadb.rule=HostSNI(`*`)"
      - "traefik.tcp.routers.mariadb.entrypoints=mariadb"
      - "traefik.tcp.routers.mariadb.service=mariadb-svc"
      - "traefik.tcp.services.mariadb-svc.loadbalancer.server.port=3306"
    networks:
      - web

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    environment:
     - PMA_HOST=db
     - PMA_USER=root
     - PMA_PASSWORD=root
     - MYSQL_ROOT_PASSWORD=root
     - PMA_ABSOLUTE_URI=https://magento2.local/phpmyadmin
#     ports:
#     - 8080:80
#    labels:
        #- "traefik.enable=true"
        #- "traefik.docker.network=web"
        #- "traefik.http.routers.phpmyadmin.rule=Host(`magento2.local`) && PathPrefix(`/phpmyadmin`)"
        #- "traefik.http.services.phpmyadmin.loadbalancer.server.port=80"
        # # https
        # #- "traefik.http.routers.magento2-phpmyadmin.rule=Host(`magento2.local`) && PathPrefix(`/phpmyadmin`)"
        # - "traefik.http.routers.magento2-phpmyadmin.service=magento2-phpmyadmin"
        # - "traefik.http.services.magento2-phpmyadmin.loadbalancer.server.port=80"
        # # http
        # - "traefik.http.routers.magento2-phpmyadmin-http.entrypoints=http"
        # - "traefik.http.middlewares.magento2-phpmyadmin-http.redirectscheme.scheme=https"
        # #- "traefik.http.routers.magento2-phpmyadmin-http.rule=Host(`magento2.local`) && Path(`/phpmyadmin`)"
        # - "traefik.http.routers.magento2-phpmyadmin-http.service=magento2-phpmyadmin"
        # # https tls
        # - "traefik.http.routers.magento2-phpmyadmin.entrypoints=https"
        # - "traefik.http.routers.magento2-phpmyadmin.tls=true"
        # - "traefik.http.routers.magento2-phpmyadmin.tls.certresolver=http"
        # # strip prefix
        # #- "traefik.http.routers.magento2-phpmyadmin.rule=Host(`magento2.local`) && Path(`/phpmyadmin`)"
        # - "traefik.http.routers.magento2-phpmyadmin.rule=Host(`magento2.local`) && PathPrefix(`/phpmyadmin{regex:$$|/.*}`)"
        # - "traefik.http.routers.magento2-phpmyadmin.middlewares=phpmyadmin-stripprefix"
        # - "traefik.http.middlewares.phpmyadmin-stripprefix.stripprefix.prefixes=/phpmyadmin"
        
        #- "traefik.http.routers.phpmyadmin.entrypoints=https"
        #- "traefik.http.services.phpmyadmin.loadbalancer.server.port=80"
        #- "traefik.http.routers.phpmyadmin.rule=Host(`magento2.local`) && PathPrefix(`/phpmyadmin{regex:$$|/.*}`)"
        #- "traefik.http.routers.phpmyadmin.rule=Host(`magento2.local`) && PathPrefixStrip(`/phpmyadmin/`)"
        #- "traefik.http.routers.phpmyadmin.rule=Host(`magento2.local`) && PathPrefix(`/phpmyadmin{regex:$$|/.*}`)"
        #- "traefik.http.routers.phpmyadmin.middlewares=phpmyadmin-stripprefix"
        #- "traefik.http.middlewares.phpmyadmin-stripprefix.stripprefix.prefixes=/phpmyadmin/"
    networks:
      - web

  redis:
    image: redis
#    ports:
##     - 6379
    networks:
      - web

  redis-session:
    image: redis
#    ports:
#     - 6379
    networks:
      - web

  mailhog:
    image: mailhog/mailhog
#    ports:
#      - 1025:1025
#      - 8025:8025
    networks:
      - web

# TODO: RabbitMC
# TODO: ElasticSearch

networks:
  web:
    external: true

volumes:
  dbdata:
    driver: local

Composer may be install due to xdebug and/or php memory limits....
https://stackoverflow.com/questions/32573924/composer-hanging-while-updating-dependencies

Also on some OS I have had to do this in the past.

sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"

https://stackoverflow.com/questions/28436237/why-is-php-composer-so-slow

I left it over lunch and it eventually chugged along.

I can't seem to login to the admin user, maybe I just need to reinstall.

Composer was still slow, logged in as root and updated it.
composer self-update

Disable xdebug on cli? I didn't notice any impact.
It also downloads from http not https.
composer config --global repo.packagist composer https://packagist.org
https://stackoverflow.com/questions/28436237/why-is-php-composer-so-slow

Dev mode

./magento deploy:mode:set developer.

Install sample data.

./magento sampledata:deploy

Supply keys again? dang it does not save them.

Upgrade to apply the sample data changes.

./magento setup:upgrade

I'll update this ticket/comment with more info later when I come back to attempting this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant