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

ENH: Add version and compose check to workflow #50

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions .github/workflows/cloud_chatops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,41 @@ jobs:
context: "{{defaultContext}}:cloud-chatops"
tags: "harbor.stfc.ac.uk/stfc-cloud-staging/cloud-chatops:${{ steps.commit_sha.outputs.sha_short }}"


check_version_update:
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v4
with:
ref: 'master'
path: 'main'

- name: Checkout current working branch
uses: actions/checkout@v4
with:
path: 'branch'

- name: Compare versions
if: ${{ github.ref != 'refs/heads/master' }}
uses: stfc/check-version-action@main
with:
app_version_path: "cloud-chatops/version.txt"
docker_compose_path: "cloud-chatops/docker-compose.yaml"

- name: Log App Success
if: ${{ env.app_updated == 'true' }}
run: |
echo "App version has been updated correctly!"

- name: Log Compose Success
if: ${{ env.compose_updated == 'true' }}
run: |
echo "Compose version has been updated correctly!"

push_prod_image_harbor:
runs-on: ubuntu-latest
needs: test_and_lint
needs: [test_and_lint, check_version_update]
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
Expand All @@ -101,17 +133,8 @@ jobs:
id: release_tag
run: echo "version=$(cat cloud-chatops/version.txt)" >> $GITHUB_OUTPUT

- name: Check if release file has updated
uses: dorny/paths-filter@v2
id: release_updated
with:
filters: |
version:
- 'cloud-chatops/version.txt'

- name: Build and push on version change
uses: docker/build-push-action@v6
if: steps.release_updated.outputs.version == 'true'
with:
cache-from: type=gha
cache-to: type=gha,mode=max
Expand Down
41 changes: 26 additions & 15 deletions cloud-chatops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ These slash commands can be run in any channel the application has access to.<br

#### Scheduled Events:
Using the [schedule](https://pypi.org/project/schedule/) library functions are triggered on a weekly basis.<br>
Events are defined in the `schedule_jobs` function:<br>
Events are defined in the `main.py/schedule_jobs` function:<br>
- `run_global_reminder()`: Sends a message to the pull request channel with every open pull request across the repositories in a thread.
- `run_personal_reminder()`: Sends a message to each user directly with a thread of their open pull requests.

Expand All @@ -44,31 +44,41 @@ The latest version can be found in [version.txt](version.txt)<br>
docker run -v $HOME/cloud_chatops_secrets/:/usr/src/app/cloud_chatops_secrets/ cloud_chatops -d
```
- ```shell
# Pull from harbor and run
# First log in to harbor
docker login -u <username> harbor.stfc.ac.uk

# Then either:

# Run container directly, specifying a version
docker run -v $HOME/cloud_chatops_secrets/:/usr/src/app/cloud_chatops_secrets/ harbor.stfc.ac.uk/stfc-cloud/cloud-chatops:<version> -d
#
# or
#
# Use Docker Compose in cloud-chatops folder, which will always contain latest image version
docker compose up -d
```

#### Running from source:
You can run the code from [main.py](src/main.py).<br>
It's always recommended to create a [virtual environment](https://docs.python.org/3/library/venv.html)
for the application to run before installing dependencies.
- ```shell
# Install Venv module
python3 -m venv my_venv
# Activate venv
source my_venv/bin/activate
# Install requirements
pip3 install -r requirements.txt
# Run app
python3 cloud-chatops/src/main.py prod
```






### Requirements:

Two files required for the deployment of this application: `config.yml` and `secrets.json`.<br>
These should be stored in `$HOME/cloud_chatops_secrets` on the host system.<br>

#### Config
#### Config:
The application configuration is stored in [config.yml](template_config.yml).
This includes information such as username mapping, repositories to check and default values.<br>
Slack Channel and Member IDs can be found in Slack by:<br>
Expand Down Expand Up @@ -105,13 +115,7 @@ defaults: # Default values for application variables
# The actual channel messages are sent to can be specified in the code.
channel: CH12NN34 # Slack channel ID
```
#### Secrets

The application needs secrets for Slack and GitHub.<br>
TODO: How to run your own Slack application or find on slack marketplace.<br>
A GitHub Personal Access Token is needed to bypass rate limiting and allows access to private repositories.<br>
Documentation on how to create a GitHub personal access token can be found
[here](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).<br>
#### Secrets:
The `secrets.json` file should look like the below and there is a template [here](template_secrets.json)
```json
{
Expand All @@ -120,3 +124,10 @@ The `secrets.json` file should look like the below and there is a template [here
"GITHUB_TOKEN": "<your-token>"
}
```
Slack:<br>
- TODO: How to create your own Slack application.<br>

GitHub:<br>
- A GitHub Personal Access Token is needed to bypass rate limiting and allows access to private repositories.<br>
- Documentation on how to create a GitHub personal access token can be found
[here](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).<br>
2 changes: 1 addition & 1 deletion cloud-chatops/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
cloud_chatops:
image: harbor.stfc.ac.uk/stfc-cloud/cloud-chatops:1.1.0
image: harbor.stfc.ac.uk/stfc-cloud/cloud-chatops:2.0.2
volumes:
- $HOME/cloud_chatops_secrets/:/usr/src/app/cloud_chatops_secrets/
31 changes: 9 additions & 22 deletions cloud-chatops/template_config.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
---
maintainer: AB12CD34 # Slack Member ID of the application maintainer
maintainer: <maintainers_member_id>

user-map: # Dictionary of GitHub username to Slack Member ID
my_github_username: AB12CD34
other_github_username: EF56GH78
user-map:
<user_github_username>: <user_member_id>

repos: # Dictionary of owners and repositories
organisation1:
- repo1 # E.g. github.com/organisation1/repo1
- repo2
- repo3
organisation2:
- repo1 # E.g. github.com/organisation2/repo1
- repo2
- repo3
repos:
<organisation>:
- <repo>

defaults: # Default values for application variables
# Default author will be assigned to pull requests where the PR author is not in the above user map.
# Usually team lead or senior staff member.
author: WX67YZ89 # Slack member ID

# Default channel is where the pull requests will be posted.
# It's recommended to set this as a "maintenance" / "dev" channel in case the application goes awry.
# The actual channel messages are sent to can be specified in the code.
channel: CH12NN34 # Slack channel ID
defaults:
author: <author_member_id>
channel: <reminder_channel_id>
2 changes: 1 addition & 1 deletion cloud-chatops/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1
Copy link
Contributor

Choose a reason for hiding this comment

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

This version is also being used in this open PR: #59 - which PR needs to be reviewed and merged first to use this version?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have left them both as the same version. When one of them (either) is merged then the other will be rebased and updated. If I were to change this PR to 2 versions ahead (2.0.3) there would be a chance of a version being skipped.

2.0.2