All checks were successful
continuous-integration/drone/push Build is passing
105 lines
4.0 KiB
Markdown
105 lines
4.0 KiB
Markdown
# Drone CI/CD Pipeline - Hello World Example with Cleanup
|
|
|
|
This project demonstrates a simple Drone CI/CD pipeline that outputs a "Hello, World!" message and then performs a cleanup of any created data. It is designed to show the basics of defining a pipeline in Drone, including running commands and performing cleanup at the end of the pipeline.
|
|
|
|
## Pipeline Overview
|
|
|
|
This pipeline contains two main steps:
|
|
|
|
1. **Hello World**: A simple step that prints "Hello, World!" to verify that the pipeline is running correctly.
|
|
2. **Cleanup**: A cleanup step that removes any files or data created during the pipeline execution (for example, temporary files).
|
|
|
|
The purpose of this pipeline is to:
|
|
|
|
* Ensure that the Drone setup is working.
|
|
* Demonstrate a simple pipeline structure.
|
|
* Show how to perform cleanup after pipeline steps.
|
|
|
|
## How to Use
|
|
|
|
To use this pipeline:
|
|
|
|
1. Ensure that you have Drone set up and running in your environment.
|
|
2. Add the `.drone.yml` file to the root directory of your repository.
|
|
3. Push your changes to the repository. Drone will automatically detect the `.drone.yml` file and run the pipeline.
|
|
|
|
## Prerequisites
|
|
|
|
* A working Drone server and Drone runner.
|
|
* The repository must be connected to Drone.
|
|
|
|
## Running the Pipeline
|
|
|
|
After pushing the `.drone.yml` file to your repository:
|
|
|
|
1. Drone will trigger a build.
|
|
2. The "Hello, World!" step will execute and print the message to the console.
|
|
3. After that, the cleanup step will execute, deleting any temporary data or files created.
|
|
|
|
## Structure of `.drone.yml`
|
|
|
|
```yaml
|
|
---
|
|
kind: pipeline
|
|
name: hello-world-pipeline
|
|
steps:
|
|
- name: hello-world
|
|
image: alpine:latest
|
|
commands:
|
|
- echo "Hello, World! Everything is running fine!"
|
|
|
|
- name: cleanup
|
|
image: alpine:latest
|
|
commands:
|
|
- echo "Cleaning up any created data..."
|
|
- rm -rf /tmp/* # Example cleanup, adjust based on what needs cleanup
|
|
- echo "Cleanup complete!"
|
|
```
|
|
|
|
**Explanation of Key Sections:**
|
|
|
|
* **`kind: pipeline`**: Defines the type of pipeline (in this case, it's a pipeline).
|
|
* **`name: hello-world-pipeline`**: The name of the pipeline (you can give it any name you prefer).
|
|
* **`steps`**: A list of steps that define the actions to be executed in the pipeline. Each step runs a Docker container (using a specified image) and can include commands to execute.
|
|
|
|
**Steps Breakdown:**
|
|
|
|
* **`hello-world` step:**
|
|
* `name: hello-world`: The name of the step.
|
|
* `image: alpine:latest`: The `alpine:latest` Docker image is used because it's small and has basic utilities.
|
|
* `commands`: The `echo` command prints "Hello, World!" to verify that the pipeline is running.
|
|
* **`cleanup` step:**
|
|
* `name: cleanup`: The name of the cleanup step.
|
|
* `image: alpine:latest`: Again, `alpine:latest` is used here for the cleanup process.
|
|
* `commands`: The `rm -rf /tmp/*` command is an example cleanup that deletes temporary files. You can replace this with other cleanup commands based on your project's requirements.
|
|
|
|
## Example Cleanup
|
|
|
|
In this example, the cleanup step is as simple as removing files from `/tmp`:
|
|
|
|
```bash
|
|
- rm -rf /tmp/*
|
|
```
|
|
|
|
This is just a placeholder for any cleanup logic. Depending on your project, you may need to clean up:
|
|
|
|
* Temporary files or directories created during the build.
|
|
* Build artifacts (like compiled files, logs, etc.).
|
|
* Any other resources used during the pipeline execution.
|
|
|
|
**Customizing Cleanup:**
|
|
|
|
If your project creates files or directories that need to be cleaned up, replace the `rm -rf /tmp/*` command with commands suited for your environment, such as:
|
|
|
|
```bash
|
|
- rm -rf /build/output/*
|
|
- rm -rf /logs/*
|
|
- docker volume prune -f # Remove unused Docker volumes, if relevant
|
|
```
|
|
|
|
## Conclusion
|
|
|
|
This `.drone.yml` provides a simple example of how to structure a Drone CI/CD pipeline that runs a "Hello, World!" message and cleans up any created data afterward. It's a good starting point for more complex pipelines.
|
|
|
|
Feel free to extend and customize the pipeline by adding more steps for building, testing, or deploying your application!
|