Skip to main content

How do I deploy my Symfony API - - Deploy best php training trivandrum

How do I deploy my Symfony API -  - Deploy

Workflow

workflows:
  version: 2
  build_and_deploy-workflow:
    jobs:
      - build
      - deploy_to_live:
          requires:
            - deploy_to_live_approval
          filters:
            branches:
              only:
                - master

      - deploy_to_live_approval:
          type: approval
          requires:
            - build
The circle CI approve button

The deploy job

version: 2
executorType: machine
jobs:
  build: # this is the job that pushes the images to the registry 
    # ...

  deploy_to_live: # this is the job that effectively deploys to live 
    working_directory: ~/my_ap
    environment:
      - DOCKER_HOST: "tcp://myapp-manager.yyy.local:2375"
    steps:
      - *helpers_system_basic
      - *helpers_docker
      - run: sudo apt-get -qq -y install openvpn
      - checkout
      - add_ssh_keys:
          fingerprints:
            - "af:83:39:00:ad:af:83:39:00:ad:af:83:39:00:ad:99"  # import VPN private key
      - run:
          name: Connect to VPN
          command: |
            sudo openvpn --daemon --cd .circleci/vpn-live --config my-vpn-config.ovpn
            while ! (echo "$DOCKER_HOST" | sed 's/tcp:\/\///'|sed 's/:/ /' |xargs nc -w 2) ;  do sleep 1; done

      - deploy:
          name: Deploy
          command: |
            docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASS
            docker stack deploy live --compose-file=docker-compose.live.yml --with-registry-auth

Step by step

Preparation

environment:
       - DOCKER_HOST: "tcp://myapp-manager.yyy.local:2375"`
- *helpers_system_basic # use basic system configurations  helper
- *helpers_docker # use basic docker installation  helper
- run: sudo apt-get -qq -y install openvpn # install openvpn client
- checkout # checkout the source code

Credentials

- add_ssh_keys:
  fingerprints:
    - "af:83:39:00:ad:af:83:39:00:ad:af:83:39:00:ad:99" 

VPN

- run:
  name: Connect to VPN
  command: |
    sudo openvpn --daemon --cd .circleci/vpn-live --config my-vpn-config.ovpn
    while ! (echo "$DOCKER_HOST" | sed 's/tcp:\/\///'|sed 's/:/ /' |xargs nc -w 2) ;  do sleep 1; done

The deploy

- deploy:
  name: Deploy
  command: |
    docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASS
    docker stack deploy live --compose-file=docker-compose.live.yml --with-registry-auth
export DB_USER="$LIVE_DB_USER"
export DB_PWD="$LIVE_DB_PWD"
docker stack deploy live --compose-file=docker-compose.live.yml --with-registry-auth
source exports_live_vars.sh
docker stack deploy live --compose-file=docker-compose.live.yml --with-registry-auth

The docker-compose.live.yml

# docker-compose.live.yml
version: '3.3'
services:
    php:
        image: goetas/api-php:master 
        deploy:
          replicas: 6
          update_config:
            parallelism: 2
            delay: 30s
          restart_policy:
            condition: on-failure                 
    www:
        image: goetas/api-nginx:master
        deploy:
          replicas: 6
          update_config:
            parallelism: 2
            delay: 30s
          restart_policy:
            condition: on-failure            
        ports:
            - "80:80"

Conclusion

Comments