Skip to content

Commit

Permalink
chore: unify naming pattern for containers (serious-scaffold#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
huxuan authored Feb 7, 2024
1 parent 029d877 commit 7716738
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
]
}
},
"image": "ghcr.io/serious-scaffold/ss-python:dev-py3.12",
"image": "ghcr.io/serious-scaffold/ss-python/dev:py3.12",
// Force the image update to ensure the latest version which might be a bug.
// Reference: https://github.com/microsoft/vscode-remote-release/issues/9391
"initializeCommand": "docker pull ghcr.io/serious-scaffold/ss-python:dev-py3.12",
"initializeCommand": "docker pull ghcr.io/serious-scaffold/ss-python/dev:py3.12",
// Use a targeted named volume for .venv folder to improve disk performance.
// Reference: https://code.visualstudio.com/remote/advancedcontainers/improve-performance#_use-a-targeted-named-volume
"mounts": [
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:
with:
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:build-cache-dev-py${{ matrix.python-version }}
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:build-cache-dev-py${{ matrix.python-version }},mode=max
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }}
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }},mode=max
file: .devcontainer/Dockerfile
provenance: false
push: true
tags: |
ghcr.io/${{ github.repository }}:dev-py${{ matrix.python-version }}
ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }}
target: dev
strategy:
matrix:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ jobs:
with:
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:build-cache-dev-py${{ matrix.python-version }}
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:build-cache-dev-py${{ matrix.python-version }},mode=max
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }}
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }},mode=max
file: .devcontainer/Dockerfile
provenance: false
push: true
tags: |
ghcr.io/${{ github.repository }}:dev-py${{ matrix.python-version }}
ghcr.io/${{ github.repository }}:dev-py${{ matrix.python-version }}-${{ github.ref_name }}
ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }}
ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }}-${{ github.ref_name }}
target: dev
- name: Build and push prod container
env:
Expand All @@ -87,13 +87,13 @@ jobs:
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
PDM_BUILD_SCM_VERSION=${{ github.ref_name }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:build-cache-dev-py${{ matrix.python-version }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }}
file: .devcontainer/Dockerfile
provenance: false
push: true
tags: |
ghcr.io/${{ github.repository }}:prod-py${{ matrix.python-version }}
ghcr.io/${{ github.repository }}:prod-py${{ matrix.python-version }}-${{ github.ref_name }}
ghcr.io/${{ github.repository }}:py${{ matrix.python-version }}
ghcr.io/${{ github.repository }}:py${{ matrix.python-version }}-${{ github.ref_name }}
target: prod
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ stages:
default:
before_script:
- env | sort
image: ${CI_REGISTRY_IMAGE}:dev-py3.12
image: ${CI_REGISTRY_IMAGE}/dev:py3.12
include: .gitlab/workflows/**.yml
2 changes: 1 addition & 1 deletion .gitlab/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ci:
coverage_format: cobertura
path: coverage.xml
coverage: /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/
image: ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION}
image: ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION}
interruptible: true
parallel:
matrix:
Expand Down
6 changes: 3 additions & 3 deletions .gitlab/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ dev-container-publish:
- |
docker buildx build . \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION} \
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION},mode=max \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION},mode=max \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION} \
--target dev
services:
- docker:dind
Expand Down
14 changes: 7 additions & 7 deletions .gitlab/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@ container-publish:
- |
docker buildx build . \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION} \
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION},mode=max \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION},mode=max \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
--target dev
- |
docker buildx build . \
--build-arg PDM_BUILD_SCM_VERSION=${CI_COMMIT_TAG} \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ${CI_REGISTRY_IMAGE}:prod-py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}:prod-py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
--tag ${CI_REGISTRY_IMAGE}:py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}:py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
--target prod
services:
- docker:dind
Expand Down
4 changes: 2 additions & 2 deletions docs/dev/proj.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pipx install copier
:::{tab-item} GitHub
:sync: github
Open the [Dev Container Workflow](https://github.com/serious-scaffold/ss-python/actions/workflows/devcontainer.yml) page and run the workflow from the default branch.
Navigate to the [Dev Container Workflow](https://github.com/serious-scaffold/ss-python/actions/workflows/devcontainer.yml) page and run workflow from the default branch. The container will be named following pattern `ghcr.io/serious-scaffold/ss-python/dev:py<PYTHON_VERSION>`, for example, `ghcr.io/serious-scaffold/ss-python/dev:py3.12`.
```{image} /_static/images/bootstrap-dev-container-github.png
:alt: Bootstrap Dev Container on GitHub.
Expand All @@ -67,7 +67,7 @@ pipx install copier
:::{tab-item} GitLab
:sync: gitlab
Open the [Run pipeline](https://gitlab.com/serious-scaffold/ss-python/-/pipelines/new) page and run pipeline for the default branch.
Navigate to the [Run pipeline](https://gitlab.com/serious-scaffold/ss-python/-/pipelines/new) page and run pipeline for the default branch. The container will be named following pattern `registry.gitlab.com/serious-scaffold/ss-python/dev:py<PYTHON_VERSION>`, for example, `registry.gitlab.com/serious-scaffold/ss-python/dev:py3.12`.
```{image} /_static/images/bootstrap-dev-container-gitlab.png
:alt: Bootstrap Dev Container on GitLab.
Expand Down
12 changes: 9 additions & 3 deletions docs/dev/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ The release process includes the following tasks:

1. Publish a new GitHub Release.
1. Build and publish the documentation to GitHub Pages.
1. Build and publish the Python package to the configured package repository.
1. Build and publish the Development and Production Containers to GitHub Packages.
1. Build and publish the Python package to the designated package repository.
1. Build and publish the Development and Production Containers with the build cache to GitHub Packages.
1. The Production Container is tagged as `ghcr.io/serious-scaffold/ss-python:py<PYTHON_VERSION>` for the latest version and `ghcr.io/serious-scaffold/ss-python:py<PYTHON_VERSION>-<PROJECT_VERSION>` for archives.
1. The Development Container is tagged as `ghcr.io/serious-scaffold/ss-python/dev:py<PYTHON_VERSION>` for the latest version and `ghcr.io/serious-scaffold/ss-python/dev:py<PYTHON_VERSION>-<PROJECT_VERSION>` for archives.
1. Build cache for the Development Container is tagged as `ghcr.io/serious-scaffold/ss-python/dev-cache:py<PYTHON_VERSION>`.

:::

Expand All @@ -22,7 +25,10 @@ The release process includes the following tasks:
1. Publish a new GitLab Release.
1. Build and publish the documentation to GitLab Pages.
1. Build and publish the Python package to the configured package repository.
1. Build and publish the Development and Production Containers to GitLab Container Registry.
1. Build and publish the Development and Production Containers with build cache to GitLab Container Registry.
1. The Production Container is tagged as `registry.gitlab.com/serious-scaffold/ss-python:py<PYTHON_VERSION>` for the latest version and `registry.gitlab.com/serious-scaffold/ss-python:py<PYTHON_VERSION>-<PROJECT_VERSION>` for archives.
1. The Development Container is tagged as `registry.gitlab.com/serious-scaffold/ss-python/dev:py<PYTHON_VERSION>` for the latest version and `registry.gitlab.com/serious-scaffold/ss-python/dev:py<PYTHON_VERSION>-<PROJECT_VERSION>` for archives.
1. Build cache for the Development Container is tagged as `registry.gitlab.com/serious-scaffold/ss-python/dev-cache:py<PYTHON_VERSION>`.

:::

Expand Down
4 changes: 2 additions & 2 deletions template/.devcontainer/devcontainer.json.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
]
}
},
"image": "{{ container_registry_host }}/{{ repo_namespace }}/{{ repo_name }}:dev-py{{ default_py }}",
"image": "{{ container_registry_host }}/{{ repo_namespace }}/{{ repo_name }}/dev:py{{ default_py }}",
// Force the image update to ensure the latest version which might be a bug.
// Reference: https://github.com/microsoft/vscode-remote-release/issues/9391
"initializeCommand": "docker pull {{ container_registry_host }}/{{ repo_namespace }}/{{ repo_name }}:dev-py{{ default_py }}",
"initializeCommand": "docker pull {{ container_registry_host }}/{{ repo_namespace }}/{{ repo_name }}/dev:py{{ default_py }}",
// Use a targeted named volume for .venv folder to improve disk performance.
// Reference: https://code.visualstudio.com/remote/advancedcontainers/improve-performance#_use-a-targeted-named-volume
"mounts": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:
with:
build-args: |
PYTHON_VERSION={{ '${{ matrix.python-version }}' }}
cache-from: type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}:build-cache-dev-py{{ '${{ matrix.python-version }}' }}
cache-to: type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}:build-cache-dev-py{{ '${{ matrix.python-version }}' }},mode=max
cache-from: type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}/dev-cache:py{{ '${{ matrix.python-version }}' }}
cache-to: type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}/dev-cache:py{{ '${{ matrix.python-version }}' }},mode=max
file: .devcontainer/Dockerfile
provenance: false
push: true
tags: |
ghcr.io/{{ '${{ github.repository }}' }}:dev-py{{ '${{ matrix.python-version }}' }}
ghcr.io/{{ '${{ github.repository }}' }}/dev:py{{ '${{ matrix.python-version }}' }}
target: dev
strategy:
matrix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ jobs:
with:
build-args: |
PYTHON_VERSION={{ '${{ matrix.python-version }}' }}
cache-from: type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}:build-cache-dev-py{{ '${{ matrix.python-version }}' }}
cache-to: type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}:build-cache-dev-py{{ '${{ matrix.python-version }}' }},mode=max
cache-from: type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}/dev-cache:py{{ '${{ matrix.python-version }}' }}
cache-to: type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}/dev-cache:py{{ '${{ matrix.python-version }}' }},mode=max
file: .devcontainer/Dockerfile
provenance: false
push: true
tags: |
ghcr.io/{{ '${{ github.repository }}' }}:dev-py{{ '${{ matrix.python-version }}' }}
ghcr.io/{{ '${{ github.repository }}' }}:dev-py{{ '${{ matrix.python-version }}' }}-{{ '${{ github.ref_name }}' }}
ghcr.io/{{ '${{ github.repository }}' }}/dev:py{{ '${{ matrix.python-version }}' }}
ghcr.io/{{ '${{ github.repository }}' }}/dev:py{{ '${{ matrix.python-version }}' }}-{{ '${{ github.ref_name }}' }}
target: dev
- name: Build and push prod container
env:
Expand All @@ -88,13 +88,13 @@ jobs:
build-args: |
PYTHON_VERSION={{ '${{ matrix.python-version }}' }}
PDM_BUILD_SCM_VERSION={{ '${{ github.ref_name }}' }}
cache-from: type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}:build-cache-dev-py{{ '${{ matrix.python-version }}' }}
cache-from: type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}/dev-cache:py{{ '${{ matrix.python-version }}' }}
file: .devcontainer/Dockerfile
provenance: false
push: true
tags: |
ghcr.io/{{ '${{ github.repository }}' }}:prod-py{{ '${{ matrix.python-version }}' }}
ghcr.io/{{ '${{ github.repository }}' }}:prod-py{{ '${{ matrix.python-version }}' }}-{{ '${{ github.ref_name }}' }}
ghcr.io/{{ '${{ github.repository }}' }}:py{{ '${{ matrix.python-version }}' }}
ghcr.io/{{ '${{ github.repository }}' }}:py{{ '${{ matrix.python-version }}' }}-{{ '${{ github.ref_name }}' }}
target: prod
strategy:
matrix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ stages:
default:
before_script:
- env | sort
image: ${CI_REGISTRY_IMAGE}:dev-py{{ default_py }}
image: ${CI_REGISTRY_IMAGE}/dev:py{{ default_py }}
include: .gitlab/workflows/**.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ci:
coverage_format: cobertura
path: coverage.xml
coverage: /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/
image: ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION}
image: ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION}
interruptible: true
parallel:
matrix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ dev-container-publish:
- |
docker buildx build . \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION} \
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION},mode=max \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION},mode=max \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION} \
--target dev
services:
- docker:dind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ container-publish:
- |
docker buildx build . \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION} \
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION},mode=max \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION},mode=max \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
--target dev
- |
docker buildx build . \
--build-arg PDM_BUILD_SCM_VERSION=${CI_COMMIT_TAG} \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ${CI_REGISTRY_IMAGE}:prod-py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}:prod-py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
--tag ${CI_REGISTRY_IMAGE}:py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}:py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
--target prod
services:
- docker:dind
Expand Down
4 changes: 2 additions & 2 deletions template/docs/dev/proj.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pipx install copier

:::{tab-item} GitHub
:sync: github
Open the [Dev Container Workflow](https://github.com/{{ repo_namespace }}/{{ repo_name }}/actions/workflows/devcontainer.yml) page and run the workflow from the default branch.
Navigate to the [Dev Container Workflow](https://github.com/{{ repo_namespace }}/{{ repo_name }}/actions/workflows/devcontainer.yml) page and run workflow from the default branch. The container will be named following pattern `ghcr.io/{{ repo_namespace }}/{{ repo_name }}/dev:py<PYTHON_VERSION>`, for example, `ghcr.io/{{ repo_namespace }}/{{ repo_name }}/dev:py3.12`.

```{image} /_static/images/bootstrap-dev-container-github.png
:alt: Bootstrap Dev Container on GitHub.
Expand All @@ -67,7 +67,7 @@ pipx install copier

:::{tab-item} GitLab
:sync: gitlab
Open the [Run pipeline](https://gitlab.com/{{ repo_namespace }}/{{ repo_name }}/-/pipelines/new) page and run pipeline for the default branch.
Navigate to the [Run pipeline](https://gitlab.com/{{ repo_namespace }}/{{ repo_name }}/-/pipelines/new) page and run pipeline for the default branch. The container will be named following pattern `registry.gitlab.com/{{ repo_namespace }}/{{ repo_name }}/dev:py<PYTHON_VERSION>`, for example, `registry.gitlab.com/{{ repo_namespace }}/{{ repo_name }}/dev:py3.12`.

```{image} /_static/images/bootstrap-dev-container-gitlab.png
:alt: Bootstrap Dev Container on GitLab.
Expand Down
Loading

0 comments on commit 7716738

Please sign in to comment.