Skip to content

Commit

Permalink
add unique image tagging, update contributing doc
Browse files Browse the repository at this point in the history
  • Loading branch information
thetoolsmith committed Dec 23, 2024
1 parent 8738c8f commit e6fab9a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
27 changes: 16 additions & 11 deletions .github/workflows/build_and_publish_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
working-directory: './images'
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
uses: actions/checkout@v4

- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v3
Expand All @@ -24,27 +24,32 @@ jobs:
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: Git SHA
shell: bash
run: |
echo "git_sha=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
- name: 'Build and Publish alpine image'
run: |
docker build -t ghcr.io/cfpb/regtech/sbl/alpine:3.18 -f Dockerfile-alpine .
docker push ghcr.io/cfpb/regtech/sbl/alpine:3.18
docker build -t ghcr.io/cfpb/regtech/sbl/alpine:3.18_${{env.git_sha}} -f Dockerfile-alpine .
docker push ghcr.io/cfpb/regtech/sbl/alpine:3.18_${{env.git_sha}}
- name: 'Build and Publish python-alpine image'
run: |
docker build -t ghcr.io/cfpb/regtech/sbl/python-alpine:3.12 -f Dockerfile-python-alpine .
docker push ghcr.io/cfpb/regtech/sbl/python-alpine:3.12
docker build -t ghcr.io/cfpb/regtech/sbl/python-alpine:3.12_${{env.git_sha}} -f Dockerfile-python-alpine .
docker push ghcr.io/cfpb/regtech/sbl/python-alpine:3.12_${{env.git_sha}}
- name: 'Build and Publish nginx-alpine image'
run: |
docker build -t ghcr.io/cfpb/regtech/sbl/nginx-alpine:1.27 -f Dockerfile-nginx-alpine .
docker push ghcr.io/cfpb/regtech/sbl/nginx-alpine:1.27
docker build -t ghcr.io/cfpb/regtech/sbl/nginx-alpine:1.27_${{env.git_sha}} -f Dockerfile-nginx-alpine .
docker push ghcr.io/cfpb/regtech/sbl/nginx-alpine:1.27_${{env.git_sha}}
- name: 'Build and Publish node-js-alpine image'
run: |
docker build -t ghcr.io/cfpb/regtech/sbl/node-js-alpine:3.20 -f Dockerfile-node-js-alpine .
docker push ghcr.io/cfpb/regtech/sbl/node-js-alpine:3.20
docker build -t ghcr.io/cfpb/regtech/sbl/node-js-alpine:3.20_${{env.git_sha}} -f Dockerfile-node-js-alpine .
docker push ghcr.io/cfpb/regtech/sbl/node-js-alpine:3.20_${{env.git_sha}}
- name: 'Build and Publish python-ubi8 image'
run: |
docker build -t ghcr.io/cfpb/regtech/sbl/python-ubi8:3.12 -f Dockerfile-python-ubi8 .
docker push ghcr.io/cfpb/regtech/sbl/python-ubi8:3.12
docker build -t ghcr.io/cfpb/regtech/sbl/python-ubi8:3.12_${{env.git_sha}} -f Dockerfile-python-ubi8 .
docker push ghcr.io/cfpb/regtech/sbl/python-ubi8:3.12_${{env.git_sha}}
17 changes: 11 additions & 6 deletions .github/workflows/build_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
working-directory: './images'
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
uses: actions/checkout@v4

- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v3
Expand All @@ -22,22 +22,27 @@ jobs:
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: Git SHA
shell: bash
run: |
echo "git_sha=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
- name: 'Build alpine image'
run: |
docker build -t ghcr.io/cfpb/regtech/sbl/alpine:3.18 -f Dockerfile-alpine .
docker build -t ghcr.io/cfpb/regtech/sbl/alpine:3.18_${{env.git_sha}} -f Dockerfile-alpine .
- name: 'Build python-alpine image'
run: |
docker build -t ghcr.io/cfpb/regtech/sbl/python-alpine:3.12 -f Dockerfile-python-alpine .
docker build -t ghcr.io/cfpb/regtech/sbl/python-alpine:3.12_${{env.git_sha}} -f Dockerfile-python-alpine .
- name: 'Build nginx-alpine image'
run: |
docker build -t ghcr.io/cfpb/regtech/sbl/nginx-alpine:1.27 -f Dockerfile-nginx-alpine .
docker build -t ghcr.io/cfpb/regtech/sbl/nginx-alpine:1.27_${{env.git_sha}} -f Dockerfile-nginx-alpine .
- name: 'Build node-js-alpine image'
run: |
docker build -t ghcr.io/cfpb/regtech/sbl/node-js-alpine:3.20 -f Dockerfile-node-js-alpine .
docker build -t ghcr.io/cfpb/regtech/sbl/node-js-alpine:3.20_${{env.git_sha}} -f Dockerfile-node-js-alpine .
- name: 'Build python-ubi8 image'
run: |
docker build -t ghcr.io/cfpb/regtech/sbl/python-ubi8:3.12 -f Dockerfile-python-ubi8 .
docker build -t ghcr.io/cfpb/regtech/sbl/python-ubi8:3.12_${{env.git_sha}} -f Dockerfile-python-ubi8 .
28 changes: 26 additions & 2 deletions images/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,31 @@

Reference [Github's documentation](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry) as needed.

## Authenticating with GHCR

## Pipeline Build and Publish Core Images
We now have a GHA pipeline to build and publish these base images to the GHCR.

#### On Pull Requests
[build_images](../.github/workflows/build_images.yml) - runs on Pull Requests to test the image build only.

#### On Merge to Main
[build_and_publish_images](../.github/workflows/build_and_publish_images.yml) - runs on Merge to Main. This workflow will build and publish the images to Github Container Registry (GHCR).

> **NOTE** The `build_and_publish_images` workflow is also scheduled to run weekly every Sunday at 5 AM to help keep the base images up-to-date with the latest security patches and such.
#### Core Image tagging
We now add a unique tag to each published set of images that are included in the `build_and_publish_images` workflow.
Tagging is using standard git sha shortend and appended to the image tag.

Example image with new tag format: `ghcr.io/cfpb/regtech/sbl/python-alpine:3.12_xxxxxxxx`

This will allow applications to pin to specific builds in the event a new change is introduced to latest that doesn't play nice with the application.

---

## Local Machine build and push core images (old depracated method)

#### Authenticating with GHCR

Generate a classic PAT token with the `read:packages`, `write:packages`, and `delete:packages` permissions.

Expand All @@ -13,7 +37,7 @@ $ echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
> Login Succeeded
```

## Build and push to GCR
#### Build and push to GCR

```bash
$ docker build -t ghcr.io/cfpb/regtech/sbl/alpine:3.18 -f Dockerfile-alpine .
Expand Down

0 comments on commit e6fab9a

Please sign in to comment.