This project demonstrates how to containerize a simple C application using Docker and automate its build, testing, vulnerability scanning, and deployment using GitHub Actions. The project builds a Docker image of the application, scans for vulnerabilities with Trivy, and pushes the Docker image to Docker Hub if it passes security checks.
- Dockerfile: Defines the multi-stage build process for the Docker image, compiling the C application in a build environment and copying the compiled binary to a smaller runtime image.
- hello.c: C code that includes a simple "Hello World" program and a basic test to verify functionality.
- containerize-C-Application.yml: GitHub Actions workflow file that automates building, testing, vulnerability scanning, and pushing the Docker image to Docker Hub.
To run the project and test it locally using Docker:
- Clone the Repository:
git clone <repository-url> cd <repository-directory>
- Build the Docker Image:
docker build -t hello:latest . - Run the Docker Container:
docker run hello:latest
- Run Trivy for Vulnerability Scanning (Optional): Install Trivy locally and scan your Docker image:
trivy image hello:latest
To run the project and test it locally without using Docker:
- Clone the Repository:
git clone <repository-url> cd <repository-directory>
- Compile the Application:
gcc -o helloworld hello.c
- Run the Application:
./helloworld
This will print Hello World to the terminal and run a basic test to verify that the output is correct.
To securely push images to Docker Hub, add the following secrets in your GitHub repository settings:
- DOCKER_USERNAME: Your Docker Hub username.
- DOCKER_PASSWORD: Your Docker Hub password.
This GitHub Actions workflow is triggered on a push to the main branch or can be manually triggered. It performs the following steps:
- Checks out the code from the repository.
- Verifies that GCC is installed.
- Compiles the C code to create a binary.
- Runs tests to verify functionality.
- Builds a Docker image of the application.
- Installs Trivy for vulnerability scanning.
- Scans the Docker image for high and critical vulnerabilities.
- If the image passes the scan, it is pushed to Docker Hub.
This project is licensed under the MIT License. Let me know if you need any further modifications or additions!