Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Dmitry-Popovichev
Copy link
Contributor

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.

…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.
Copy link

codecov bot commented Oct 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.68%. Comparing base (eb9d469) to head (9f0050a).

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.
📢 Have feedback on the report? Share it here.

cloud-chatops/README.md Show resolved Hide resolved
cloud-chatops/cron-clone.sh Outdated Show resolved Hide resolved
cloud-chatops/cron-clone.sh Outdated Show resolved Hide resolved
git clone https://github.com/stfc/cloud-docker-images.git

cd $HOME/cloud-docker-images/cloud-chatops
docker compose up -d

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?

Copy link
Contributor Author

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).

Copy link
Member

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.
@Dmitry-Popovichev Dmitry-Popovichev marked this pull request as ready for review October 29, 2024 16:09
Comment on lines 8 to 10
git fetch && git clean -fxd && git reset --hard origin/main

cd $HOME/cloud-docker-images/cloud-chatops
Copy link
Collaborator

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

Copy link
Contributor Author

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.
Comment on lines +130 to +138
```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.
```
Copy link
Member

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.

Suggested change
```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/...`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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_-]*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*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_-]*

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants