Skip to content

Commit 66c8235

Browse files
authored
Merge pull request #41 from FireTail-io/feat/fire-1839/publish-to-ghcr
feat/fire-1839/publish-to-ghcr
2 parents 105c86b + e53dd13 commit 66c8235

File tree

3 files changed

+123
-86
lines changed

3 files changed

+123
-86
lines changed
Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
name: Draft Release On Push To Main And Push Prerelease Image To ECR
1+
name: Draft Release
2+
run-name: '@${{ github.triggering_actor }}: ${{ github.ref_name }}: ${{ github.event_name }}'
23

34
on:
45
push:
56
branches:
67
- main
78

89
env:
9-
AWS_REGION: us-east-1
10-
ECR_REGISTRY: public.ecr.aws/x7v5r9e4
11-
ECR_REPOSITORY: firetail-code-repository-scanner
12-
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: firetail-code-repository-scanner
12+
1313
jobs:
1414
draft-release:
1515
name: Draft Release
@@ -23,34 +23,58 @@ jobs:
2323

2424
steps:
2525
- name: Checkout
26-
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
26+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2727

2828
- name: Draft Release
2929
id: draft_release
30-
uses: release-drafter/release-drafter@569eb7ee3a85817ab916c8f8ff03a5bd96c9c83e
30+
uses: release-drafter/release-drafter@09c613e259eb8d4e7c81c2cb00618eb5fc4575a7 # v5.25.0
3131
env:
3232
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3333

34-
- name: Configure AWS Credentials
35-
uses: aws-actions/configure-aws-credentials@67fbcbb121271f7775d2e7715933280b06314838
36-
with:
37-
aws-region: ${{ env.AWS_REGION }}
38-
role-to-assume: ${{ secrets.AWS_ACCOUNT_ROLE_ARN }}
39-
role-session-name: git-api-discovery-publish-action-draft
34+
- name: Set Image Tags From Release Output
35+
run: |
36+
cat <<HEREDOC >>${{ github.env }}
37+
PRERELEASE_IMAGE_TAG=${{ steps.draft_release.outputs.tag_name }}-prerelease
38+
PRERELEASE_LAMBDA_IMAGE_TAG=${{ steps.draft_release.outputs.tag_name }}-lambda-prerelease
39+
HEREDOC
4040
41-
- name: Login to ECR and build, tag & push prerelease images
42-
env:
43-
PRERELEASE_IMAGE_TAG: ${{ steps.draft_release.outputs.tag_name }}-prerelease
44-
PRERELEASE_LAMBDA_IMAGE_TAG: ${{ steps.draft_release.outputs.tag_name }}-lambda-prerelease
41+
- name: Log In to the Container Registry
42+
run: |
43+
docker login ${{ env.REGISTRY }} \
44+
--username ${{ github.actor }} \
45+
--password-stdin <<<${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Build and Push Runtime Image
4548
run: |
46-
aws ecr-public get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin public.ecr.aws
47-
docker build --target runtime -t $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_IMAGE_TAG -f build_setup/Dockerfile .
48-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_IMAGE_TAG
49-
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest-prerelease
50-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_IMAGE_TAG
51-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest-prerelease
52-
docker build --target runtime-lambda -t $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_LAMBDA_IMAGE_TAG -f build_setup/Dockerfile .
53-
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_LAMBDA_IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest-lambda-prerelease
54-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_LAMBDA_IMAGE_TAG
55-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest-lambda-prerelease
56-
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_IMAGE_TAG" >> $GITHUB_OUTPUT
49+
docker build \
50+
--target runtime \
51+
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PRERELEASE_IMAGE_TAG }} \
52+
--file build_setup/Dockerfile \
53+
"${PWD}"
54+
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PRERELEASE_IMAGE_TAG }} \
55+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-prerelease
56+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PRERELEASE_IMAGE_TAG }}
57+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-prerelease
58+
59+
- name: Build and Push Lambda Image
60+
run: |
61+
docker build \
62+
--target runtime-lambda \
63+
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PRERELEASE_LAMBDA_IMAGE_TAG }} \
64+
--file build_setup/Dockerfile \
65+
"${PWD}"
66+
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PRERELEASE_LAMBDA_IMAGE_TAG }} \
67+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-lambda-prerelease
68+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PRERELEASE_LAMBDA_IMAGE_TAG }}
69+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-lambda-prerelease
70+
71+
- name: Summarize Workflow Run
72+
run: |
73+
cat <<HEREDOC >>${GITHUB_STEP_SUMMARY}
74+
## Successfully Pushed:
75+
76+
- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PRERELEASE_IMAGE_TAG }}
77+
- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-prerelease
78+
- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PRERELEASE_LAMBDA_IMAGE_TAG }}
79+
- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-lambda-prerelease
80+
HEREDOC
Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
1-
name: Pull Prerelease Image From ECR And Push As Release Image When Draft Release Is Published
2-
1+
name: Publish Release
2+
run-name: '@${{ github.triggering_actor }}: ${{ github.ref_name }}: ${{ github.event_name }}: ${{ github.event.action }}'
33
on:
44
release:
55
types: [published]
66

77
env:
8-
AWS_REGION: us-east-1
9-
ECR_REGISTRY: public.ecr.aws/x7v5r9e4
10-
ECR_REPOSITORY: firetail-code-repository-scanner
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: firetail-code-repository-scanner
1110

1211
jobs:
1312
publish-release:
1413
name: Publish Release
15-
1614
environment: prod
17-
1815
runs-on: ubuntu-latest
1916
permissions:
2017
id-token: write
2118
contents: read
2219
pull-requests: write
2320

2421
steps:
25-
- name: Get release
26-
id: get_release
27-
uses: bruceadams/get-release@74c3d60f5a28f358ccf241a00c9021ea16f0569f
28-
env:
29-
GITHUB_TOKEN: ${{ github.token }}
30-
- name: Configure AWS Credentials
31-
uses: aws-actions/configure-aws-credentials@67fbcbb121271f7775d2e7715933280b06314838
32-
with:
33-
aws-region: ${{ env.AWS_REGION }}
34-
role-to-assume: ${{ secrets.AWS_ACCOUNT_ROLE_ARN }}
35-
role-session-name: git-api-discovery-publish-action-prod
36-
37-
- name: Pull prerelease images from ECR, retag them as a releases, and push them back to ECR with their new tags
38-
id: build-image
39-
env:
40-
PRERELEASE_IMAGE_TAG: ${{ steps.get_release.outputs.tag_name }}-prerelease
41-
PRERELEASE_LAMBDA_IMAGE_TAG: ${{ steps.get_release.outputs.tag_name }}-lambda-prerelease
42-
IMAGE_TAG: ${{ steps.get_release.outputs.tag_name }}
43-
LAMBDA_IMAGE_TAG: ${{ steps.get_release.outputs.tag_name }}-lambda
22+
23+
- name: Log In to the Container Registry
24+
run: |
25+
docker login ${{ env.REGISTRY }} \
26+
--username ${{ github.actor }} \
27+
--password-stdin <<<${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Publish Prelease Lambda Image as Full Release
4430
run: |
45-
aws ecr-public get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin public.ecr.aws
46-
docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_IMAGE_TAG
47-
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
48-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
49-
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
50-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
51-
docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_LAMBDA_IMAGE_TAG
52-
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_LAMBDA_IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$LAMBDA_IMAGE_TAG
53-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$LAMBDA_IMAGE_TAG
54-
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$PRERELEASE_LAMBDA_IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest-lambda
55-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest-lambda
56-
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
31+
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-prerelease
32+
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-prerelease \
33+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
34+
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-prerelease \
35+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
36+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
37+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
38+
39+
- name: Publish Prelease Lambda Image as Full Release
40+
run: |
41+
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-lambda-prerelease
42+
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-lambda-prerelease \
43+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-lambda
44+
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-lambda-prerelease \
45+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-lambda
46+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-lambda
47+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-lambda
48+
49+
- name: Summarize Workflow Run
50+
run: |
51+
cat <<HEREDOC >>${GITHUB_STEP_SUMMARY}
52+
## Successfully Pushed:
53+
54+
- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
55+
- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
56+
- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-lambda
57+
- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-lambda
58+
HEREDOC

README.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
This Docker image will discover APIs in your GitHub account by scanning for openapi/swagger specifications in your repositories, as well as generating them via static code analysis. It will create an API per repository, and potentially multiple collections for that API, in the FireTail SaaS Platform.
44

5-
6-
75
## Quickstart
86

97
First, clone this repo and build the scanner's image:
108

119
```bash
1210
git clone git@github.com:FireTail-io/github-api-discovery.git
1311
cd github-api-discovery
14-
docker build --rm -t firetail-io/github-api-discovery:latest -f build_setup/Dockerfile . --target runtime
12+
docker build \
13+
--tag firetail-io/github-api-discovery:latest \
14+
--file build_setup/Dockerfile \
15+
--target runtime \
16+
.
1517
```
1618

1719
Make a copy of the provided [config-example.yml](./config-example.yml) and call it `config.yml`, then edit it for your use case.
@@ -31,36 +33,45 @@ Find a full list of environment variables under [Environment Variables](#environ
3133
Once you have created a classic GitHub personal access token and a FireTail app token, you can run the scanner image:
3234

3335
```bash
34-
export GITHUB_TOKEN=YOUR_GITHUB_TOKEN
35-
export FIRETAIL_APP_TOKEN=YOUR_FIRETAIL_APP_TOKEN
36-
docker run --rm -e GITHUB_TOKEN=${GITHUB_TOKEN} -e FIRETAIL_APP_TOKEN=${FIRETAIL_APP_TOKEN} --mount type=bind,source="$(pwd)"/config.yml,target=/config.yml,readonly firetail-io/github-api-discovery:latest
36+
docker run --rm \
37+
--env GITHUB_TOKEN=${YOUR_GITHUB_TOKEN} \
38+
--env FIRETAIL_APP_TOKEN=${YOUR_FIRETAIL_APP_TOKEN} \
39+
--mount type=bind,source="${PWD}"/config.yml,target=/config.yml,readonly \
40+
firetail-io/github-api-discovery:latest
3741
```
3842

39-
40-
4143
## Tests
4244

4345
The tests can be run using the provided Dockerfile:
4446

4547
```bash
46-
docker build --rm -t firetail-io/github-api-discovery:test-python -f build_setup/Dockerfile . --target test-python
48+
docker build --rm \
49+
--tag firetail-io/github-api-discovery:test-python \
50+
--file build_setup/Dockerfile \
51+
--target test-python \
52+
.
4753
```
4854

4955
Tests for the Golang analyser can also be run separately using the provided Dockerfile to yield a html coverage report:
5056

5157
```bash
52-
docker build --rm -t firetail-io/github-api-discovery:test-golang -f build_setup/Dockerfile . --target test-golang
53-
docker run --rm --entrypoint cat firetail-io/github-api-discovery:test-golang coverage.html > golang-coverage.html
58+
docker build \
59+
--tag firetail-io/github-api-discovery:test-golang \
60+
--file build_setup/Dockerfile \
61+
--target test-golang \
62+
.
63+
64+
docker run --rm \
65+
--volume ./coverage:/coverage \
66+
firetail-io/github-api-discovery:test-golang \
67+
cp coverage.html /coverage/golang-coverage.html
5468
```
5569

56-
57-
5870
## Environment Variables
5971

60-
| Variable Name | Description | Required? | Default |
61-
| -------------------- | ------------------------------------------------------------ | --------- | ------------------------------------------------ |
62-
| `GITHUB_TOKEN` | A classic GitHub personal access token. | Yes ✅ | None |
63-
| `FIRETAIL_APP_TOKEN` | An app token from the Firetail SaaS. | Yes ✅ | None |
64-
| `FIRETAIL_API_URL` | The URL of the Firetail SaaS' API. | No ❌ | `"https://api.saas.eu-west-1.prod.firetail.app"` |
65-
| `LOGGING_LEVEL` | The logging level provided to python's [logging](https://docs.python.org/3/library/logging.html#logging-levels) library. | No ❌ | `"INFO"` |
66-
72+
| Variable Name | Description | Required? | Default |
73+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------ | --------- | ------------------------------------------------ |
74+
| `GITHUB_TOKEN` | A classic GitHub personal access token. | Yes ✅ | None |
75+
| `FIRETAIL_APP_TOKEN` | An app token from the Firetail SaaS. | Yes ✅ | None |
76+
| `FIRETAIL_API_URL` | The URL of the Firetail SaaS' API. | No ❌ | `"https://api.saas.eu-west-1.prod.firetail.app"` |
77+
| `LOGGING_LEVEL` | The logging level provided to python's [logging](https://docs.python.org/3/library/logging.html#logging-levels) library. | No ❌ | `"INFO"` |

0 commit comments

Comments
 (0)