Skip to content

Commit f4f60ab

Browse files
authored
Merge pull request #13 from ONS-Innovation/KEH-1962-Concourse
KEH-1962 - Concourse
2 parents db005fb + 438c4f4 commit f4f60ab

12 files changed

Lines changed: 567 additions & 194 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@ONS-Innovation/keh-dev

.github/pull_request_template.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# What type of PR is this? (check all applicable)
2+
3+
- [ ] Refactor
4+
- [ ] Feature
5+
- [ ] Bug Fix
6+
- [ ] Optimization
7+
- [ ] Documentation Update
8+
9+
## What
10+
11+
Describe what you have changed and why.
12+
13+
## Testing
14+
15+
Have any new tests been added as part of this issue? If not, try to explain why test coverage is not needed here.
16+
17+
- [ ] Yes
18+
- [ ] No
19+
Please write a brief description of why test coverage is not necessary here.
20+
- [ ] Not as part of this ticket. (Could be done at a later point)
21+
22+
## Documentation
23+
24+
Has any new documentation been written as part of this issue? We should try to keep documentation up to date
25+
as new code is added, rather than leaving it for the future.
26+
27+
- [ ] Yes
28+
- [ ] No
29+
Please write a brief description of why documentation is not necessary here.
30+
- [ ] Not as part of this ticket. (Could be done at a later point)
31+
32+
## Related issues
33+
34+
Provide links to any related issues.
35+
36+
## How to review
37+
38+
Describe the steps required to test the changes.

README.md

Lines changed: 130 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,158 @@
1-
# GitHub Scraper Batch
1+
# GitHub Statistics Scraper
22

3-
A Python script that scrapes GitHub repositories and saves the data to an S3 bucket. This repository utilises the scheduled batch module to deploy the service as a batch job on AWS.
3+
A Python script to collect GitHub repository statistics and store them within an S3 bucket.
4+
This repository uses the scheduled batch module to deploy the service as a batch job on AWS.
45

5-
This project utilises the [GitHub API Package](https://github.com/ONS-Innovation/github-api-package) GraphQL interface to get data from GitHub.
6+
This tool is responsible for populating the Statistics page within the Digital Landscape ([View Repository](https://github.com/ONSdigital/keh-digital-landscape)).
67

7-
The script is run from the command line using the following command:
8+
## Disclaimer
89

9-
### Prerequisites:
10+
This repository is quite old and is due a fair bit of work to bring it up to the standards of our more recent repositories.
11+
12+
There are a few `TODOs` scattered throughout the README and codebase that will need to be addressed.
13+
14+
---
15+
16+
## Table of Contents
17+
18+
- [GitHub Statistics Scraper](#github-statistics-scraper)
19+
- [Disclaimer](#disclaimer)
20+
- [Table of Contents](#table-of-contents)
21+
- [Prerequisites:](#prerequisites)
22+
- [Getting started](#getting-started)
23+
- [Deployment](#deployment)
24+
- [Deployments with Concourse](#deployments-with-concourse)
25+
- [Allowlisting your IP](#allowlisting-your-ip)
26+
- [Setting up a pipeline](#setting-up-a-pipeline)
27+
- [Prod deployment](#prod-deployment)
28+
- [Triggering a pipeline](#triggering-a-pipeline)
29+
- [Destroying a pipeline](#destroying-a-pipeline)
30+
- [Manual Deployment](#manual-deployment)
31+
- [Testing](#testing)
32+
- [Linting and formatting](#linting-and-formatting)
33+
34+
## Prerequisites:
1035

1136
- Python 3.10+
1237
- Poetry
1338
- AWS CLI
1439
- Make
1540

16-
### Getting started
41+
## Getting started
1742

18-
Setup:
19-
```bash
20-
make install
21-
```
43+
1. Install Dependencies:
44+
45+
```bash
46+
make install
47+
```
48+
49+
2. Export Environment Variables
50+
51+
```bash
52+
# AWS
53+
export AWS_ACCESS_KEY_ID=<KEY>
54+
export AWS_SECRET_ACCESS_KEY=<SECRET>
55+
export AWS_DEFAULT_REGION=<REGION>
56+
export AWS_SECRET_NAME=/<env>/github-tooling-suite/<onsdigital/ons-innovation>
57+
58+
# GitHub
59+
export GITHUB_APP_CLIENT_ID=<CLIENT_ID>
60+
export GITHUB_ORG=<onsdigital/ons-innovation>
61+
62+
# Other
63+
export SOURCE_BUCKET=<BUCKET_NAME>
64+
export SOURCE_KEY=<KEY>
65+
export BATCH_SIZE=<BATCH_SIZE>
66+
export ENVIRONMENT=<development/production>
67+
```
68+
69+
| Variable | Description |
70+
| --------------- | ---------------------------------------------------------------------------------- |
71+
| `source_bucket` | The S3 bucket that will store the output of the script. |
72+
| `source_key` | The key of the file that will store the output of the script. |
73+
| `batch_size` | The number of repositories that will be scraped in each batch. |
74+
| `environment` | Determines where to save the results. `development`: locally, `production`: to S3. |
75+
76+
3. Run the script:
77+
78+
```bash
79+
make run
80+
```
81+
82+
## Deployment
83+
84+
### Deployments with Concourse
85+
86+
#### Allowlisting your IP
87+
88+
To setup the deployment pipeline with concourse, you must first allowlist your IP address on the Concourse
89+
server. IP addresses are flushed everyday at 00:00 so this must be done at the beginning of every working day
90+
whenever the deployment pipeline needs to be used. Follow the instructions on the Confluence page (SDP Homepage > SDP Concourse > Concourse Login) to
91+
login. All our pipelines run on sdp-pipeline-prod, whereas sdp-pipeline-dev is the account used for
92+
changes to Concourse instance itself. Make sure to export all necessary environment variables from sdp-pipeline-prod (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN).
93+
94+
#### Setting up a pipeline
95+
96+
When setting up our pipelines, we use ecs-infra-user on sdp-dev to be able to interact with our infrastructure on AWS. The credentials for this are stored on
97+
AWS Secrets Manager so you do not need to set up anything yourself.
98+
99+
To set the pipeline, run the following script:
22100

23-
Export AWS environment variables:
24101
```bash
25-
export AWS_ACCESS_KEY_ID=<KEY>
26-
export AWS_SECRET_ACCESS_KEY=<SECRET>
27-
export AWS_DEFAULT_REGION=<REGION>
28-
export AWS_SECRET_NAME=/<env>/github-tooling-suite/<onsdigital/ons-innovation>
102+
chmod u+x ./concourse/scripts/set_pipeline.sh
103+
./concourse/scripts/set_pipeline.sh
29104
```
30105

31-
Export GitHub environment variables:
106+
Note that you only have to run chmod the first time running the script in order to give permissions.
107+
This script will set the branch and pipeline name to whatever branch you are currently on. It will also set the image tag on ECR to 7 characters of the current branch name if running on a branch other than main. For main, the ECR tag will be the latest release tag on the repository that has semantic versioning(vX.Y.Z).
108+
109+
The pipeline name itself will usually follow a pattern as follows: `github-statistics-scraper-<branch-name>` for any non-main branch and `github-statistics-scraper` for the main/master branch.
110+
111+
#### Prod deployment
112+
113+
To deploy to prod, it is required that a Github Release is made on Github. The release is required to follow semantic versioning of vX.Y.Z.
114+
115+
A manual trigger is to be made on the pipeline name `github-statistics-scraper > deploy-after-github-release` job through the Concourse CI UI. This will create a github-create-tag resource that is required on the `github-statistics-scraper > build-and-push-prod` job. Then the prod deployment job is also through a manual trigger ensuring that prod is only deployed using the latest GitHub release tag in the form of vX.Y.Z and is manually controlled.
116+
117+
#### Triggering a pipeline
118+
119+
Once the pipeline has been set, you can manually trigger a dev build on the Concourse UI, or run the following command for non-main branch deployment:
120+
32121
```bash
33-
export GITHUB_APP_CLIENT_ID=<CLIENT_ID>
34-
export GITHUB_ORG=<onsdigital/ons-innovation>
122+
fly -t aws-sdp trigger-job -j github-statistics-scraper-<branch-name>/build-and-push-dev
35123
```
36124

37-
Export other environment variables:
125+
and for main branch deployment:
126+
38127
```bash
39-
export SOURCE_BUCKET=<BUCKET_NAME>
40-
export SOURCE_KEY=<KEY>
41-
export BATCH_SIZE=<BATCH_SIZE>
42-
export ENVIRONMENT=<development/production>
128+
fly -t aws-sdp trigger-job -j github-statistics-scraper/build-and-push-dev
43129
```
44130

45-
- The source_bucket is the S3 bucket that will store the output of the script.
46-
- The source_key is the key of the file that will store the output of the script.
47-
- The batch_size is the number of repositories that will be scraped in each batch.
48-
- The environment determines where to save the results. Development: locally, Production: to S3
131+
#### Destroying a pipeline
132+
133+
To destroy the pipeline, run the following command:
49134

50-
Run:
51135
```bash
52-
make run
136+
fly -t aws-sdp destroy-pipeline -p github-statistics-scraper-<branch-name>
53137
```
54138

55-
### Linting and formatting
139+
**It is unlikely that you will need to destroy a pipeline, but the command is here if needed.**
140+
141+
**Note:** This will not destroy any resources created by Terraform. You must manually destroy these resources using Terraform.
142+
143+
### Manual Deployment
144+
145+
TODO: Add manual deployment instructions for deploying the script without Concourse.
146+
147+
## Testing
148+
149+
TODO: Add testing instructions.
150+
151+
TODO: Add tests.
152+
153+
## Linting and formatting
154+
155+
TODO: Update linting and formatting practices to bring the repo in line with common team practices.
56156

57157
Install dev dependencies:
58158
```bash
@@ -78,38 +178,3 @@ Run black:
78178
```bash
79179
make black
80180
```
81-
82-
### Deployments with Concourse
83-
84-
#### Allowlisting your IP
85-
To setup the deployment pipeline with concourse, you must first allowlist your IP address on the Concourse
86-
server. IP addresses are flushed everyday at 00:00 so this must be done at the beginning of every working day
87-
whenever the deployment pipeline needs to be used. Follow the instructions on the Confluence page (SDP Homepage > SDP Concourse > Concourse Login) to
88-
login. All our pipelines run on sdp-pipeline-prod, whereas sdp-pipeline-dev is the account used for
89-
changes to Concourse instance itself. Make sure to export all necessary environment variables from sdp-pipeline-prod (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN).
90-
91-
#### Setting up a pipeline
92-
When setting up our pipelines, we use ecs-infra-user on sdp-dev to be able to interact with our infrastructure on AWS. The credentials for this are stored on
93-
AWS Secrets Manager so you do not need to set up anything yourself.
94-
95-
To set the pipeline, run the following script:
96-
```bash
97-
chmod u+x ./concourse/scripts/set_pipeline.sh
98-
./concourse/scripts/set_pipeline.sh github-scraper
99-
```
100-
Note that you only have to run chmod the first time running the script in order to give permissions.
101-
This script will set the branch and pipeline name to whatever branch you are currently on. It will also set the image tag on ECR to the current commit hash at the time of setting the pipeline.
102-
103-
The pipeline name itself will usually follow a pattern as follows: `<repo-name>-<branch-name>`
104-
If you wish to set a pipeline for another branch without checking out, you can run the following:
105-
```bash
106-
./concourse/scripts/set_pipeline.sh github-scraper <branch_name>
107-
```
108-
109-
If the branch you are deploying is "main" or "master", it will trigger a deployment to the sdp-prod environment. To set the ECR image tag, you must draft a Github release pointing to the latest release of the main/master branch that has a tag in the form of vX.Y.Z. Drafting up a release will automatically deploy the latest version of the main/master branch with the associated release tag, but you can also manually trigger a build through the Concourse UI or the terminal prompt.
110-
111-
#### Triggering a pipeline
112-
Once the pipeline has been set, you can manually trigger a build on the Concourse UI, or run the following command:
113-
```bash
114-
fly -t aws-sdp trigger-job -j github-scraper-<branch-name>/build-and-push
115-
```

0 commit comments

Comments
 (0)