Skip to content

Commit bbb9d96

Browse files
authored
Merge pull request #172 from stfc/cloud_chatops_docker_secrets
Cloud chatops docker secrets
2 parents 76c8542 + e08da95 commit bbb9d96

22 files changed

+431
-115
lines changed

.github/workflows/cloud_chatops.yaml

+87-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
name: CI/CD Cloud ChatOps
1+
name: Cloud Chatops
22

33
on:
44
push:
55
branches:
66
- master
77
pull_request:
88
paths:
9-
- "cloud_chatops/**"
109
- ".github/workflows/cloud_chatops.yaml"
10+
- "cloud_chatops/**"
1111

1212
jobs:
13-
Pylint-Tests-Codecov:
14-
runs-on: ubuntu-20.04
13+
test_and_lint:
14+
runs-on: ${{ matrix.os }}
1515
strategy:
1616
matrix:
17+
os: ['ubuntu-20.04','ubuntu-22.04']
1718
python-version: [ "3.12", "3.x" ]
1819
steps:
1920
- uses: actions/checkout@v4
@@ -25,17 +26,95 @@ jobs:
2526

2627
- name: Install dependencies
2728
run: |
29+
cd cloud_chatops
2830
python -m pip install --upgrade pip
29-
cd cloud_chatops && pip install -r requirements.txt
31+
pip install -r requirements.txt
3032
3133
- name: Analyse with pylint
32-
run: pylint cloud_chatops --rcfile=cloud_chatops/.pylintrc
34+
run: |
35+
cd cloud_chatops
36+
pylint . --recursive=true --rcfile=.pylintrc
37+
38+
- name: Run tests
39+
run: |
40+
cd cloud_chatops
41+
python3 -m pytest tests
3342
3443
- name: Run tests and collect coverage
35-
run: cd cloud_chatops && python3 -m pytest tests --cov-report xml:coverage.xml --cov
44+
run: |
45+
cd cloud_chatops
46+
python3 -m pytest tests --cov-report xml:coverage.xml --cov
3647
3748
- name: Upload coverage to Codecov
3849
uses: codecov/codecov-action@v4
3950
with:
4051
token: ${{secrets.CODECOV_TOKEN}}
41-
files: ./cloud_chatops/coverage.xml
52+
files: cloud_chatops/coverage.xml
53+
54+
push_dev_image_harbor:
55+
runs-on: ubuntu-latest
56+
needs: test_and_lint
57+
steps:
58+
- uses: actions/checkout@v4
59+
60+
- name: Set up Docker Buildx
61+
uses: docker/setup-buildx-action@v3
62+
63+
- name: Login to Harbor
64+
uses: docker/login-action@v3
65+
with:
66+
registry: harbor.stfc.ac.uk
67+
username: ${{ secrets.STAGING_HARBOR_USERNAME }}
68+
password: ${{ secrets.STAGING_HARBOR_TOKEN }}
69+
70+
- name: Set commit SHA for later
71+
id: commit_sha
72+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
73+
74+
- name: Build and push to staging project
75+
uses: docker/build-push-action@v6
76+
with:
77+
cache-from: type=gha
78+
cache-to: type=gha,mode=max
79+
push: true
80+
context: "{{defaultContext}}:cloud_chatops"
81+
tags: "harbor.stfc.ac.uk/stfc-cloud-staging/cloud-chatops:${{ steps.commit_sha.outputs.sha_short }}"
82+
83+
push_prod_image_harbor:
84+
runs-on: ubuntu-latest
85+
needs: test_and_lint
86+
if: github.ref == 'refs/heads/main'
87+
steps:
88+
- uses: actions/checkout@v4
89+
90+
- name: Set up Docker Buildx
91+
uses: docker/setup-buildx-action@v3
92+
93+
- name: Login to Harbor
94+
uses: docker/login-action@v3
95+
with:
96+
registry: harbor.stfc.ac.uk
97+
username: ${{ secrets.HARBOR_USERNAME }}
98+
password: ${{ secrets.HARBOR_TOKEN }}
99+
100+
- name: Get release tag for later
101+
id: release_tag
102+
run: echo "version=$(cat cloud_chatops/version.txt)" >> $GITHUB_OUTPUT
103+
104+
- name: Check if release file has updated
105+
uses: dorny/paths-filter@v2
106+
id: release_updated
107+
with:
108+
filters: |
109+
version:
110+
- 'cloud_chatops/version.txt'
111+
112+
- name: Build and push on version change
113+
uses: docker/build-push-action@v6
114+
if: steps.release_updated.outputs.version == 'true'
115+
with:
116+
cache-from: type=gha
117+
cache-to: type=gha,mode=max
118+
push: true
119+
context: "{{defaultContext}}:cloud_chatops"
120+
tags: "harbor.stfc.ac.uk/stfc-cloud/cloud-chatops:${{ steps.release_tag.outputs.version }}"

cloud_chatops/.gitignore

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
../.idea/
1+
.idea/
22
__pycache__/
3-
secrets.json
4-
user_map.json
5-
repos.csv
6-
maintainer.txt
3+
tests/__pycache__/

cloud_chatops/.pylintrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
max-line-length=120
55

66
# Disable various warnings:
7+
# R0801 - Duplicate Code - Ignored to be fixed in future PRs
78

8-
disable=
9+
disable=R0801
10+
11+
[MASTER]
12+
init-hook='import sys; sys.path.append("src")'

cloud_chatops/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM python:3
2+
WORKDIR /usr/src/app
3+
COPY . .
4+
RUN pip3 install --no-cache-dir --requirement requirements.txt
5+
CMD ["python", "src/main.py"]

cloud_chatops/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Using Slack's Bolt for Python library here I have developed a Slack Application
44
This application is designed to help promote the closing of GitHub pull requests either by getting them approved and merged or closed when they go stale.<br>
55
In principle, the app will notify authors about their pull requests until they are closed.<br>
66
### Deployment
7-
The entry point for is in [main.py](main.py) which will run the application.<br>
7+
The entry point for is in [main.py](src/main.py) which will run the application.<br>
88
The required files (below) need to be in the [cloud_chatops](.) directory.<br>
99
### Functionality
1010
As of current, the application gets all open pull requests from any Cloud owned repository and will send a message to our pull-request channel about each pull request notifying the author.<br>

cloud_chatops/docker-compose.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
cloud_chatops:
3+
image: harbor.stfc.ac.uk/stfc-cloud/cloud-chatops
4+
volumes:
5+
- $HOME/cloud_chatops_secrets/:/usr/src/app/cloud_chatops_secrets/
6+
watchtower:
7+
image: containrrr/watchtower
8+
volumes:
9+
- /var/run/docker.sock:/var/run/docker.sock
10+
- $HOME/.docker/config.json:/config.json
11+
command: --interval 60

cloud_chatops/lib/online_notif.py

-17
This file was deleted.

cloud_chatops/lib/slack_app.py

-52
This file was deleted.

cloud_chatops/main.py

-16
This file was deleted.

cloud_chatops/pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
pythonpath = lib
2+
pythonpath = src
33
testpaths = tests
44
python_files = *.py
55
python_functions = test_*
File renamed without changes.

cloud_chatops/src/enum_states.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# pylint: disable=C0114
2+
from enum import Enum, auto
3+
4+
5+
class PRsFoundState(Enum):
6+
"""This Enum provides states for whether any PRs were found."""
7+
8+
PRS_FOUND = auto()
9+
NONE_FOUND = auto()

cloud_chatops/src/features/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)