NeroCube / bookmark

Place some learning resources
0 stars 0 forks source link

Drone Config #394

Open NeroCube opened 1 year ago

NeroCube commented 1 year ago

To implement Drone CI for your Python project so that a feature branch merge to the master branch triggers tests, builds a Docker image, deploys it to a server, and runs the new Docker version, you can follow these steps:

  1. Set up a Drone CI server and configure it to work with your version control system (e.g., GitHub, GitLab, Bitbucket).
  2. Create a drone.yml file in the root of your project repository with the following configuration:
kind: pipeline
name: deploy-to-production

trigger:
  branch:
    - master

steps:
  - name: build
    image: python:3.8
    commands:
      - pip install -r requirements.txt
      - python setup.py build

  - name: test
    image: python:3.8
    commands:
      - python -m pytest tests/

  - name: build-docker-image
    image: plugins/docker
    settings:
      repo: my-docker-repo
      username: my-docker-username
      password: my-docker-password
      tags: latest

  - name: deploy-to-server
    image: plugins/ssh
    settings:
      host: my-server-ip
      username: my-server-username
      password: my-server-password
      port: 22
      target: /home/my-user/my-app
      script:
        - docker-compose up -d
  1. In the trigger section, specify that the pipeline should be triggered when a merge event occurs on the master branch.
  2. In the steps section, specify the sequence of steps you want to run, including building your Python code, running tests, building a Docker image, and deploying to your server.
  3. The build step installs dependencies and builds your Python code, while the test step runs your tests.
  4. The build-docker-image step uses the plugins/docker plugin to build a Docker image and push it to your Docker repository. Make sure to replace my-docker-repo, my-docker-username, and my-docker-password with your own values.
  5. The deploy-to-server step uses the plugins/ssh plugin to SSH into your server, deploy the new Docker image, and start the container. Make sure to replace my-server-ip, my-server-username, my-server-password, and target with your own values.
  6. Commit and push your drone.yml file to your repository. Now, when a feature branch is merged into the master branch, Drone CI will automatically run your tests, build a Docker image, deploy it to your server, and start the container.