Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 68 additions & 24 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

name: Docker Image CI

on: # yamllint disable-line rule:truthy
Expand All @@ -15,10 +14,9 @@ env:
ARTIFACT_NAME: algorithm-exercises-py_${{ github.sha }}

jobs:

build:
name: "Build Docker images"
runs-on: ubuntu-24.04
build-lint:
name: "Build Docker LINT image"
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

Expand All @@ -39,6 +37,14 @@ jobs:
with:
name: ${{ env.ARTIFACT_NAME }}_lint
path: /tmp/${{ env.ARTIFACT_NAME }}_lint.tar
build-test:
name: "Build Docker TEST image"
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: "TEST: Build and push"
uses: docker/build-push-action@v7
Expand All @@ -55,6 +61,14 @@ jobs:
name: ${{ env.ARTIFACT_NAME }}_test
path: /tmp/${{ env.ARTIFACT_NAME }}_test.tar

build-prod:
name: "Build Docker PRODUCTION image"
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: "PRODUCTION: Build and push"
uses: docker/build-push-action@v7
with:
Expand All @@ -71,11 +85,33 @@ jobs:
name: ${{ env.ARTIFACT_NAME }}_prod
path: /tmp/${{ env.ARTIFACT_NAME }}_prod.tar

lint:
run-lint-markdown:
name: "Run in docker: Markdown LINT"
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Run markdown lint
run: >
make compose/lint/markdown

run-lint-yaml:
name: "Run in docker: YAML LINT"
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Run YAML lint
run: >
make compose/lint/yaml

run-lint:
name: "Run in docker: LINT"
runs-on: ubuntu-24.04
needs: build
runs-on: ubuntu-26.04
needs: build-lint
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Download artifact
uses: actions/download-artifact@v8
with:
Expand All @@ -88,14 +124,19 @@ jobs:
docker image ls -a

- name: Run lint
run: |
docker run --rm ${{ env.IMAGE_NAME }}:lint make lint
run: >
docker
compose --profile lint
run --rm ${{ env.IMAGE_NAME }}-lint
make lint

test:
run-test:
name: "Run in docker: TEST"
runs-on: ubuntu-24.04
needs: build
runs-on: ubuntu-26.04
needs: build-test
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Download artifact
uses: actions/download-artifact@v8
with:
Expand All @@ -108,14 +149,17 @@ jobs:
docker image ls -a

- name: Run test
run: |
docker run --rm ${{ env.IMAGE_NAME }}:test make test
run: >
docker
compose --profile test
run --rm ${{ env.IMAGE_NAME }}-test
make test

# yamllint disable rule:line-length
# security:
# name: "Snyk Container"
# runs-on: ubuntu-24.04
# needs: build
# runs-on: ubuntu-26.04
# needs: build-prod
# permissions:
# actions: read
# contents: read
Expand Down Expand Up @@ -163,8 +207,8 @@ jobs:

scan:
name: "Trivy"
runs-on: ubuntu-24.04
needs: build
runs-on: ubuntu-26.04
needs: build-prod
permissions:
actions: read
contents: read
Expand All @@ -185,20 +229,20 @@ jobs:
uses: aquasecurity/trivy-action@v0.36.0
with:
image-ref: ${{ env.IMAGE_NAME }}:${{ github.sha }}
format: 'table'
format: "table"
env:
TRIVY_DB_REPOSITORY: ${{ vars.TRIVY_DB_REPOSITORY }}

- name: Run Trivy vulnerability scanner (sarif report)
uses: aquasecurity/trivy-action@v0.36.0
with:
image-ref: ${{ env.IMAGE_NAME }}:${{ github.sha }}
format: 'sarif'
output: 'trivy-results.sarif'
format: "sarif"
output: "trivy-results.sarif"
env:
TRIVY_DB_REPOSITORY: ${{ vars.TRIVY_DB_REPOSITORY }}

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
uses: github/codeql-action/upload-sarif@v4.38.0
with:
sarif_file: 'trivy-results.sarif'
sarif_file: "trivy-results.sarif"
16 changes: 2 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ FROM base AS lint
ENV WORKDIR=/app
WORKDIR ${WORKDIR}

RUN apk add --update --no-cache make nodejs npm \
&& apk add --update --no-cache yamllint \
&& npm install -g --ignore-scripts markdownlint-cli@0.49.1 \
&& npm install -g --ignore-scripts prettier@3.7.4
# Node.js required by pyright as dependency
RUN apk add --update --no-cache nodejs

# [!TIP] Use a bind-mount to "/app" to override following "copys"
# for lint and test against "current" sources in this stage
Expand All @@ -57,16 +55,6 @@ COPY ./.pylintrc ${WORKDIR}/
COPY ./.coveragerc ${WORKDIR}/
COPY ./setup.cfg ${WORKDIR}/

# markdownlint conf
COPY ./.markdownlint.json ${WORKDIR}/

# yamllint conf
COPY ./.yamllint ${WORKDIR}/
COPY ./.yamlignore ${WORKDIR}/

# JSON linting conf
COPY ./.prettierrc.yaml ${WORKDIR}/

CMD ["make", "lint"]

###############################################################################
Expand Down
22 changes: 16 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ lint/markdown:
lint/yaml:
yamllint --strict . && echo '✔ Your code looks good.'

lint: lint/markdown lint/yaml lint/json test/styling test/static
lint: test/styling test/static

lint/all: lint/markdown lint/yaml test/styling test/static

format/json:
prettier --write ./src/**/*.json
Expand Down Expand Up @@ -162,11 +164,19 @@ compose/rebuild: env
${DOCKER_COMPOSE} --profile testing build --no-cache
${DOCKER_COMPOSE} --profile production build --no-cache

compose/lint/markdown: compose/build
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make lint/markdown

compose/lint/yaml: compose/build
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make lint/yaml
compose/lint/markdown:
${DOCKER_COMPOSE} --profile lint run --rm \
--workdir /workspace \
-v "$$(pwd):/workspace" \
markdownlint --config /workspace/.markdownlint.json '/workspace/**/*.md' \
&& echo '✔ Your code looks good.'

compose/lint/yaml:
${DOCKER_COMPOSE} --profile lint run --rm \
--workdir /workspace \
-v "$$(pwd):/workspace" \
yamllint --strict . \
&& echo '✔ Your code looks good.'

compose/test/styling: compose/build
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-py-lint make test/styling
Expand Down
14 changes: 14 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ services:
- ./:/app
profiles: ["lint"]

markdownlint:
image: goncl/markdownlint-cli:latest
working_dir: /workspace
volumes:
- ./:/workspace
profiles: ["lint"]

yamllint:
image: goncl/yamllint:latest
working_dir: /workspace
volumes:
- ./:/workspace
profiles: ["lint"]

algorithm-exercises-py-dev:
image: algorithm-exercises-py:dev
build:
Expand Down