-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Added a new cron-clone.sh script and edited the README.md file #60
base: master
Are you sure you want to change the base?
Conversation
…in cloud-chatops The cron-clone.sh script can be used to automatically pull docker-compose images via the cron.hourly, cron.daily, cron.weekly, or cron.monthly directories. The README files includes how to configure this.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #60 +/- ##
=======================================
Coverage 98.68% 98.68%
=======================================
Files 12 12
Lines 608 608
=======================================
Hits 600 600
Misses 8 8 ☔ View full report in Codecov by Sentry. |
git clone https://github.com/stfc/cloud-docker-images.git | ||
|
||
cd $HOME/cloud-docker-images/cloud-chatops | ||
docker compose up -d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to do a docker-compose pull
to grab the latest image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kalibh has a script that checks for any version changes in the docker-compose file and updates it. So when we delete and pull the repo, it has the newest image (I think, if I understood correctly).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we do not use the latest
tag on our image versions, a pull
will only pull the same image that is already running. The idea being that every git clone will point to the "latest" image as the version should be updated in each pull request.
Changed the script to fetch and clean instead of deleting everything. Also added error logging.
cloud-chatops/cron-clone.sh
Outdated
git fetch && git clean -fxd && git reset --hard origin/main | ||
|
||
cd $HOME/cloud-docker-images/cloud-chatops |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this won't work as the order is back-to-front
We need to move to the git repo then update it, whereas the script attempts to update the repo then moves to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes that makes sense, cd $HOME/cloud-docker-images/cloud-chatops
was actually originally only intended for the line below, docker compose up -d
. Before the last change, we were deleting the repo with an absolute path, therefore there was no need to cd
into it. I can get that changed now, thanks!
The script now changes directory before it git fetches, cleans and resets.
```shell | ||
#Changing the file permissions. | ||
chmod +x /etc/cron.hourly/<filename> | ||
|
||
#You can test that the script is running correctly by using this command. | ||
run-parts /etc/cron.hourly | ||
|
||
#if you don't recieve any output, the script has not run. | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you try changing permisions while the file is in /etc
you may need to use sudo. We should change the permissions inside the cloned repo before we copy the file over. This means we can avoid using sudo.
e.g.
```shell | |
#Changing the file permissions. | |
chmod +x /etc/cron.hourly/<filename> | |
#You can test that the script is running correctly by using this command. | |
run-parts /etc/cron.hourly | |
#if you don't recieve any output, the script has not run. | |
``` | |
```shell | |
# Clone the repo | |
git clone https://github.com/stfc/cloud-docker-images.git | |
# Change into repo directory | |
cd cloud-docker-images/cloud-chatops | |
# Change permissions on script | |
chmod +x cron-clone.sh | |
# Copy script to etc.hourly | |
sudo cp cron-clone.sh /etc/cron.hourly/update_chatops | |
# You can test that the script is running correctly by using this command. | |
run-parts /etc/cron.hourly | |
#if you don't recieve any output, the script has not run. |
### Automatic Container Update | ||
To pull the latest `docker-compose` file automatically, you can copy the contents of the cron_clone.sh file and create a new file in either the cron.hourly, cron.daily, cron.weekly, or cron.monthly directories. These directories can be found in `$HOME/etc/...`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To pull the latest `docker-compose` file automatically, you can copy the contents of the cron_clone.sh file and create a new file in either the cron.hourly, cron.daily, cron.weekly, or cron.monthly directories. These directories can be found in `$HOME/etc/...`. | |
To pull the latest `docker-compose` file automatically, you can copy the cron_clone.sh file into any of the `cron.< hourly | daily | weekly | monthly > directories found in `/etc`. |
#if you don't recieve any output, the script has not run. | ||
``` | ||
*Please note when naming the file within $HOME/etc/..., you cannot use file fullstops '.' or file extenstions. Only valid characters are allowed [a-zA-Z0-9_-]* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*Please note when naming the file within $HOME/etc/..., you cannot use file fullstops '.' or file extenstions. Only valid characters are allowed [a-zA-Z0-9_-]* | |
*Please note when naming the file within /etc/cron.<timeframe> you cannot use file extenstions. Only valid characters are allowed [a-zA-Z0-9_-]* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we rename the file to cron-clone
then we don't have to rename the file and can just do `cp cron-clone /etc/cron.hourly
This saves debugging when someone does copy the file but doesn't change the name.
The cron-clone.sh script can be used to automatically pull docker-compose images via the cron.hourly, cron.daily, cron.weekly, or cron.monthly directories. The README files includes how to configure this.