To achieve the tasks you've outlined, you'll need to follow these steps:
- Create a GitHub Repo with HTML Page:
- Create a new GitHub repository.
- Add an HTML file (e.g.,
index.html) to the repository.
- Create a Dockerfile:
- In your GitHub repository, create a Dockerfile that defines how to build your Docker image. Here's a simple example:
# Use an official Nginx runtime as a parent image
FROM nginx:alpine
# Copy your HTML file into the Nginx web root directory
COPY index.html /usr/share/nginx/html
# Expose port 80 to listen for incoming HTTP requests
EXPOSE 80
# Start Nginx
CMD ["nginx", "-g", "daemon off;"]
- Write a Shell Script:
Create a shell script (e.g., build_and_run.sh) with the following content:
#!/bin/bash
# Clone the GitHub repo
git clone https://github.com/yourusername/your-repo.git
# Navigate to the repo directory
cd your-repo
# Build the Docker image
docker build -t your-image-name .
# Push the Docker image to Docker Hub
docker push your-dockerhub-username/your-image-name
# Run the Docker container
docker run -d -p 80:80 your-dockerhub-username/your-image-name
Make sure to replace yourusername, your-repo, your-image-name, and your-dockerhub-username with your actual GitHub and Docker Hub information.
- Execute the Shell Script via Cron:
To run the shell script every 10 minutes, you can set up a cron job. Edit your crontab file by running:
crontab -e
Then add the following line to schedule the script execution:
*/10 * * * * /path/to/build_and_run.sh
Replace /path/to/build_and_run.sh with the actual path to your shell script.
- Make Changes to
index.html:
Edit your index.html file in your GitHub repository to make the desired changes.
- Check the Browser After 15 Minutes:
After making changes to index.html, commit and push the changes to your GitHub repository. Wait for 15 minutes, and the updated content should be reflected when you access the website in your browser.
- Push the Build Shell Script to the Same Repo:
Add the build_and_run.sh shell script to your GitHub repository:
git add build_and_run.sh
git commit -m "Add build_and_run.sh script"
git push
Now you have a setup that automatically builds and deploys your HTML page using Docker, updates it every 10 minutes via a cron job, and reflects changes in the browser after 15 minutes when you make updates to index.html.
Top comments (0)