Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Latest commit

 

History

History
153 lines (113 loc) · 5.24 KB

README.production.md

File metadata and controls

153 lines (113 loc) · 5.24 KB

Ergonode production docker

Build

  1. You Must copy or clone your production backend and frontend app to the docker directory.

  2. Directory structure

    docker/
    ├── frontend
    ├── backend
    
  3. Set your build environment variables. You can use for this the .env file.

    COMPOSE_PROJECT_NAME=your-app-name
    CONTAINER_REGISTRY_BASE=your-registry-url/your-app-name

    And optionally your IMAGE tag, by default this is already set to latest.

    IMAGE_TAG=latest
  4. Build with command

    docker-compose  -f docker-compose.deploy.yml  build

    or faster build with enabled BuildKit

    COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose  -f docker-compose.deploy.yml  build
    

Test you images

  1. For testing your backend code must have must have correctly configured test tools. If you have correctly set up your testing tools you can execute the commands:

    #!/bin/bash
    
    set -eo pipefail
    
    function finish {
      docker-compose -f docker-compose.test.yml rm --stop --force
    }
    trap finish EXIT
    docker-compose -f docker-compose.test.yml up -d
    until docker-compose -f docker-compose.test.yml run --rm php bin/console doctrine:query:sql "SELECT 1" > /dev/null 2>&1; do
      sleep 1
    done
    
     docker-compose -f docker-compose.test.yml run  -e "PHP_INI_DIRECTIVES=memory_limit=-1" --rm php bin/phing test
     docker-compose -f docker-compose.test.yml run --rm nuxtjs npm run test
  2. To test your images on local machine you can use command

    docker-compose -f docker-compose.production.yml  -f docker-compose.postgres.yml up -d
    
  3. And test your app on port 80 (by default this is set in environment variable $EXPOSED_NGINX_PORT) at http://localhost

Push images to registry

  1. To push your images to your registry you need execute commands.
docker login your-registry-url
docker-compose  -f docker-compose.deploy.yml  push

Deploy the stack to the swarm

  1. You need login to your swarm server by ssh and following command execute on your docker swarm server.

  2. You need set all environment required variables described in docker-compose.production.yml and optionally in docker-compose.postgres.yml.

  3. For environmental variables, you can create a file .env.

  4. Example .env file:

      COMPOSE_PROJECT_NAME=your-app-name
      CONTAINER_REGISTRY_BASE=your-registry-url/your-app-name
    
      ...
  5. Login to your registry (if your registry require this for pulling docker images)

    docker login your-registry-url
  6. Create the your stack with docker stack deploy:

     $ env $(cat .env | grep ^[a-zA-Z] | xargs) docker stack deploy --compose-file docker-compose.production.yml --compose-file docker-compose.postgres.yml  ergonode
    
     Creating network ergonode_ergonode
     Creating service ergonode_php-messenger-export
     Creating service ergonode_rabbitmq-02
     Creating service ergonode_php-messenger-core
     Creating service ergonode_php
     Creating service ergonode_nginx
     Creating service ergonode_php-messenger-import
     Creating service ergonode_postgres
     Creating service ergonode_rabbitmq-01
     Creating service ergonode_consul
     Creating service ergonode_nuxtjs
     Creating service ergonode_php-messenger-segment
     Creating service ergonode_rabbitmq-03
     Creating service ergonode_haproxy
    

    If You have managed PostgreSQL by your provider you can skip option --compose-file docker-compose.postgres.yml

  7. Check that it’s running with docker stack services ergonode:

    $ docker stack services ergonode
    ID                  NAME                MODE                REPLICAS            IMAGE                                            PORTS
    4uwzc0p9hetl        ergonode_nginx      replicated          1/1                 docker.io/ergonode/nginx:latest      *:80->80/tcp
    q1me75mm90pw        ergonode_nuxtjs     replicated          1/1                 docker.io/ergonode/nuxtjs:latest       
    rlgcj8dyj54z        ergonode_postgres   replicated          1/1                 docker.io/ergonode/postgres:latest   
    s4hlonu65i8g        ergonode_php        replicated          1/1                 docker.io/ergonode/php:latest

    This might take some time if you have a multi-node swarm, as images need to be pulled. It may take some time if you have a multi-node, because the images have need to be pulled by swarm nodes.

    And you can test your application on port 80 (by default this is set in environment variable $EXPOSED_NGINX_PORT) at http://your-swarm-node-ip.

  8. To check your service logs you can do this with docker service logs ergonode_service_name

    $ docker   service logs -f ergonode_nginx
    ergonode_nginx.1.z8ohiml3lj9l@swarm    | 127.0.0.1 - - [25/Feb/2020:09:59:49 +0000] "GET /api/doc HTTP/1.1" 200 98347 "-" "curl/7.66.0" "-"
  9. If you want to bring down your stack then you can execute docker stack rm:

$ docker stack rm ergonode 

Removing service ergonode_nginx
Removing service ergonode_nuxtjs
Removing service ergonode_php
Removing service ergonode_postgres
Removing network ergonode_ergonode