Skip to content

Commit

Permalink
Split out lint action
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Nov 7, 2024
1 parent c6da9b7 commit d2f25ea
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 70 deletions.
23 changes: 3 additions & 20 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
image-name:
required: true
type: string
docker-context:
dockerfile-location:
required: true
type: string
base-image:
Expand All @@ -14,9 +14,6 @@ inputs:
required: false
type: string
default: app
ignore-linting-rules:
required: false
type: string

outputs:
image-id:
Expand All @@ -32,20 +29,6 @@ outputs:
runs:
using: "composite"
steps:

- uses: hadolint/[email protected]
with:
dockerfile: ${{ inputs.docker-context }}/Dockerfile
ignore: SC1091,${{ inputs.ignore-linting-rules }}
- name: ShellCheck
run: |
cd ${{ inputs.docker-context }}
[ -d "./bin" ] && shellcheck --external-sources --exclude=SC1091 ./bin/*
shellcheck --external-sources --exclude=SC2148 ./Dockerfile
shell: bash



- name: Prepare image tag
id: generate-tags
run: |
Expand All @@ -72,15 +55,15 @@ runs:
- name: Build and push images
uses: docker/build-push-action@v6
with:
context: ${{ inputs.docker-context }}
context: ${{ inputs.dockerfile-location }}
platforms: linux/amd64,linux/arm64
labels: |
runnumber=${{ github.run_id }}
build-args: |
BASE_IMAGE=${{ inputs.base-image }}
BASE_IMAGE_TAG=${{ steps.generate-tags.outputs.tag }}
TNA_DOCKER_IMAGE_VERSION=${{ steps.generate-tags.outputs.tag }}
TNA_DOCKER_IMAGE_SOURCE=${{ github.server_url }}/${{ github.repository }}/blob/main/${{ inputs.docker-context }}/Dockerfile
TNA_DOCKER_IMAGE_SOURCE=${{ github.server_url }}/${{ github.repository }}/blob/main/${{ inputs.dockerfile-location }}/Dockerfile
USER_IMAGE=${{ inputs.user-image }}
push: false
tags: ${{ steps.generate-tags.outputs.image-id }}:${{ steps.generate-tags.outputs.tag }}
Expand Down
23 changes: 23 additions & 0 deletions .github/actions/lint/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint Dockerfile

inputs:
dockerfile-location:
required: true
type: string
ignore-linting-rules:
required: false
type: string

runs:
using: "composite"
steps:
- uses: hadolint/[email protected]
with:
dockerfile: ${{ inputs.dockerfile-location }}/Dockerfile
ignore: SC1091,${{ inputs.ignore-linting-rules }}
- name: ShellCheck
run: |
cd ${{ inputs.dockerfile-location }}
[ -d "./bin" ] && shellcheck --external-sources --exclude=SC1091 ./bin/*
shellcheck --external-sources --exclude=SC2148 ./Dockerfile
shell: bash
18 changes: 9 additions & 9 deletions .github/actions/push/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ inputs:
minor-version:
required: true
type: string
docker-context:
dockerfile-location:
required: true
type: string
base-image:
Expand Down Expand Up @@ -49,15 +49,15 @@ runs:
- name: Build and push images
uses: docker/build-push-action@v6
with:
context: ${{ inputs.docker-context }}
context: ${{ inputs.dockerfile-location }}
platforms: linux/amd64,linux/arm64
labels: |
runnumber=${{ github.run_id }}
build-args: |
BASE_IMAGE=${{ inputs.base-image }}
BASE_IMAGE_TAG=${{ inputs.image-tag }}
TNA_DOCKER_IMAGE_VERSION=${{ inputs.image-tag }}
TNA_DOCKER_IMAGE_SOURCE=${{ github.server_url }}/${{ github.repository }}/blob/main/${{ inputs.docker-context }}/Dockerfile
TNA_DOCKER_IMAGE_SOURCE=${{ github.server_url }}/${{ github.repository }}/blob/main/${{ inputs.dockerfile-location }}/Dockerfile
USER_IMAGE=${{ inputs.user-image }}
push: true
tags: ${{ inputs.image-id }}:${{ inputs.image-tag }}
Expand All @@ -69,15 +69,15 @@ runs:
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v6
with:
context: ${{ inputs.docker-context }}
context: ${{ inputs.dockerfile-location }}
platforms: linux/amd64,linux/arm64
labels: |
runnumber=${{ github.run_id }}
build-args: |
BASE_IMAGE=${{ inputs.base-image }}
BASE_IMAGE_TAG=${{ inputs.major-version }}
TNA_DOCKER_IMAGE_VERSION=${{ inputs.image-tag }}
TNA_DOCKER_IMAGE_SOURCE=${{ github.server_url }}/${{ github.repository }}/blob/main/${{ inputs.docker-context }}/Dockerfile
TNA_DOCKER_IMAGE_SOURCE=${{ github.server_url }}/${{ github.repository }}/blob/main/${{ inputs.dockerfile-location }}/Dockerfile
USER_IMAGE=${{ inputs.user-image }}
push: true
tags: ${{ inputs.image-id }}:${{ inputs.major-version }}
Expand All @@ -86,15 +86,15 @@ runs:
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v6
with:
context: ${{ inputs.docker-context }}
context: ${{ inputs.dockerfile-location }}
platforms: linux/amd64,linux/arm64
labels: |
runnumber=${{ github.run_id }}
build-args: |
BASE_IMAGE=${{ inputs.base-image }}
BASE_IMAGE_TAG=${{ inputs.minor-version }}
TNA_DOCKER_IMAGE_VERSION=${{ inputs.image-tag }}
TNA_DOCKER_IMAGE_SOURCE=${{ github.server_url }}/${{ github.repository }}/blob/main/${{ inputs.docker-context }}/Dockerfile
TNA_DOCKER_IMAGE_SOURCE=${{ github.server_url }}/${{ github.repository }}/blob/main/${{ inputs.dockerfile-location }}/Dockerfile
USER_IMAGE=${{ inputs.user-image }}
push: true
tags: ${{ inputs.image-id }}:${{ inputs.minor-version }}
Expand All @@ -103,15 +103,15 @@ runs:
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v6
with:
context: ${{ inputs.docker-context }}
context: ${{ inputs.dockerfile-location }}
platforms: linux/amd64,linux/arm64
labels: |
runnumber=${{ github.run_id }}
build-args: |
BASE_IMAGE=${{ inputs.base-image }}
BASE_IMAGE_TAG=latest
TNA_DOCKER_IMAGE_VERSION=${{ inputs.image-tag }}
TNA_DOCKER_IMAGE_SOURCE=${{ github.server_url }}/${{ github.repository }}/blob/main/${{ inputs.docker-context }}/Dockerfile
TNA_DOCKER_IMAGE_SOURCE=${{ github.server_url }}/${{ github.repository }}/blob/main/${{ inputs.dockerfile-location }}/Dockerfile
USER_IMAGE=${{ inputs.user-image }}
push: true
tags: ${{ inputs.image-id }}:latest
Expand Down
86 changes: 45 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,38 @@ jobs:
runs-on: ubuntu-latest
env:
IMAGE_NAME: tna-python
# DOCKER_CONTEXT: docker/tna-python
DOCKERFILE_LOCATION: docker/tna-python
BASE_IMAGE: ghcr.io/nationalarchives/tna-python
USER_IMAGE: app
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint
uses: ./.github/actions/lint
with:
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
ignore-linting-rules: DL3002,DL3006
- name: Build
id: build
uses: ./.github/actions/build
with:
image-name: ${{ env.IMAGE_NAME }}
# image-name: tna-python
# base-image: ${{ env.BASE_IMAGE }}
base-image: ghcr.io/nationalarchives/tna-python
# docker-context: ${{ env.DOCKER_CONTEXT }}
docker-context: docker/tna-python
# user-image: ${{ env.USER_IMAGE }}
user-image: app
ignore-linting-rules: DL3002,DL3006
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
- name: Test Flask
uses: ./.github/actions/test
with:
application-repository: nationalarchives/flask-application-template
service: app
# image: ${{ env.IMAGE_NAME }}
image: tna-python
image: ${{ env.IMAGE_NAME }}
image-tag: ${{ steps.build.outputs.tag }}
- name: Test FastAPI
uses: ./.github/actions/test
with:
application-repository: nationalarchives/fastapi-application-template
service: app
# image: ${{ env.IMAGE_NAME }}
image: tna-python
image: ${{ env.IMAGE_NAME }}
image-tag: ${{ steps.build.outputs.tag }}
- name: Push
uses: ./.github/actions/push
Expand All @@ -72,12 +70,9 @@ jobs:
image-tag: ${{ steps.build.outputs.tag }}
major-version: ${{ steps.build.outputs.major-version }}
minor-version: ${{ steps.build.outputs.minor-version }}
# base-image: ${{ env.BASE_IMAGE }}
base-image: ghcr.io/nationalarchives/tna-python
# docker-context: ${{ env.DOCKER_CONTEXT }}
docker-context: docker/tna-python
# user-image: ${{ env.USER_IMAGE }}
user-image: app
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Scan
uses: ./.github/actions/scan
Expand All @@ -90,21 +85,25 @@ jobs:
runs-on: ubuntu-latest
env:
IMAGE_NAME: tna-python-root
DOCKER_CONTEXT: docker/tna-python
DOCKERFILE_LOCATION: docker/tna-python
BASE_IMAGE: ghcr.io/nationalarchives/tna-python
USER_IMAGE: root
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint
uses: ./.github/actions/lint
with:
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
ignore-linting-rules: DL3002,DL3006
- name: Build
id: build
uses: ./.github/actions/build
with:
image-name: ${{ env.IMAGE_NAME }}
base-image: ${{ env.BASE_IMAGE }}
docker-context: ${{ env.DOCKER_CONTEXT }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
ignore-linting-rules: DL3002,DL3006
- name: Test Flask
uses: ./.github/actions/test
with:
Expand All @@ -127,7 +126,7 @@ jobs:
major-version: ${{ steps.build.outputs.major-version }}
minor-version: ${{ steps.build.outputs.minor-version }}
base-image: ${{ env.BASE_IMAGE }}
docker-context: ${{ env.DOCKER_CONTEXT }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Scan
Expand All @@ -142,19 +141,23 @@ jobs:
runs-on: ubuntu-latest
env:
IMAGE_NAME: tna-python-django
DOCKER_CONTEXT: docker/tna-python-django
DOCKERFILE_LOCATION: docker/tna-python-django
BASE_IMAGE: ghcr.io/nationalarchives/tna-python
USER_IMAGE: root
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint
uses: ./.github/actions/lint
with:
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
- name: Build
id: build
uses: ./.github/actions/build
with:
image-name: ${{ env.IMAGE_NAME }}
base-image: ${{ env.BASE_IMAGE }}
docker-context: ${{ env.DOCKER_CONTEXT }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
- name: Test Django
uses: ./.github/actions/test
Expand All @@ -171,7 +174,7 @@ jobs:
major-version: ${{ steps.build.outputs.major-version }}
minor-version: ${{ steps.build.outputs.minor-version }}
base-image: ${{ env.BASE_IMAGE }}
docker-context: ${{ env.DOCKER_CONTEXT }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Scan
Expand All @@ -186,21 +189,25 @@ jobs:
runs-on: ubuntu-latest
env:
IMAGE_NAME: tna-python-django-root
DOCKER_CONTEXT: docker/tna-python-django
DOCKERFILE_LOCATION: docker/tna-python-django
BASE_IMAGE: ghcr.io/nationalarchives/tna-python-root
USER_IMAGE: root
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint
uses: ./.github/actions/lint
with:
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
ignore-linting-rules: DL3002
- name: Build
id: build
uses: ./.github/actions/build
with:
image-name: ${{ env.IMAGE_NAME }}
base-image: ${{ env.BASE_IMAGE }}
docker-context: ${{ env.DOCKER_CONTEXT }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
ignore-linting-rules: DL3002
- name: Test Django
uses: ./.github/actions/test
with:
Expand All @@ -216,7 +223,7 @@ jobs:
major-version: ${{ steps.build.outputs.major-version }}
minor-version: ${{ steps.build.outputs.minor-version }}
base-image: ${{ env.BASE_IMAGE }}
docker-context: ${{ env.DOCKER_CONTEXT }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Scan
Expand All @@ -232,28 +239,25 @@ jobs:
runs-on: ubuntu-latest
env:
IMAGE_NAME: tna-python-dev
DOCKER_CONTEXT: docker/tna-python-dev
DOCKERFILE_LOCATION: docker/tna-python-dev
BASE_IMAGE: ghcr.io/nationalarchives/tna-python-root
USER_IMAGE: root
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint
uses: ./.github/actions/lint
with:
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
ignore-linting-rules: DL3002,DL3006
- name: Build
id: build
uses: ./.github/actions/build
with:
image-name: ${{ env.IMAGE_NAME }}
base-image: ${{ env.BASE_IMAGE }}
docker-context: ${{ env.DOCKER_CONTEXT }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
ignore-linting-rules: DL3002,DL3006
- name: Test Django
uses: ./.github/actions/test
with:
application-repository: nationalarchives/django-application-template
service: app
image: ${{ env.IMAGE_NAME }}
image-tag: ${{ steps.build.outputs.tag }}
- name: Push
uses: ./.github/actions/push
with:
Expand All @@ -262,7 +266,7 @@ jobs:
major-version: ${{ steps.build.outputs.major-version }}
minor-version: ${{ steps.build.outputs.minor-version }}
base-image: ${{ env.BASE_IMAGE }}
docker-context: ${{ env.DOCKER_CONTEXT }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Scan
Expand Down

0 comments on commit d2f25ea

Please sign in to comment.