From 253ab0fd925bd41beb29747ab85298ff21e73df0 Mon Sep 17 00:00:00 2001 From: "Xuan (Sean) Hu" Date: Sun, 28 Jan 2024 23:34:03 +0800 Subject: [PATCH] chore: Adaptive container registry host. (#290) --- .vscode/settings.json | 1 + copier.yaml | 10 ++++++++++ template/.devcontainer/devcontainer.json.jinja | 4 ++-- .../{devcontainer.json => devcontainer.json.jinja} | 2 +- template/.vscode/settings.json | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) rename template/.devcontainer/prebuild/.devcontainer/{devcontainer.json => devcontainer.json.jinja} (59%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7250176e..73f2671b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -128,6 +128,7 @@ "repo_host_type", "repo_host", "page_host", + "container_registry_host", "ci", "repo_namespace", "repo_name", diff --git a/copier.yaml b/copier.yaml index 815812f4..3674abe0 100644 --- a/copier.yaml +++ b/copier.yaml @@ -95,6 +95,16 @@ page_host: help: 'Specify the host of the self-managed GitLab Pages:' type: str when: '{{ repo_host_type == "gitlab-self-managed" }}' +container_registry_host: + default: |- + [% if repo_host_type == 'github.com' -%] + ghcr.io + [%- elif repo_host_type == 'gitlab.com' -%] + registry.gitlab.com + [%- endif %] + help: 'Specify the host of the self-managed GitLab Container Registry:' + type: str + when: '{{ repo_host_type == "gitlab-self-managed" }}' repo_namespace: default: '{{ organization_name|lower|replace(" ", "-") }}' help: 'Indicate the GitHub Repository Owner or GitLab Namespace. This is typically the account name of the author or the organization:' diff --git a/template/.devcontainer/devcontainer.json.jinja b/template/.devcontainer/devcontainer.json.jinja index 71dceb39..2d0738e2 100644 --- a/template/.devcontainer/devcontainer.json.jinja +++ b/template/.devcontainer/devcontainer.json.jinja @@ -14,10 +14,10 @@ ] } }, - "image": "ghcr.io/{{ 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 ghcr.io/{{ 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": [ diff --git a/template/.devcontainer/prebuild/.devcontainer/devcontainer.json b/template/.devcontainer/prebuild/.devcontainer/devcontainer.json.jinja similarity index 59% rename from template/.devcontainer/prebuild/.devcontainer/devcontainer.json rename to template/.devcontainer/prebuild/.devcontainer/devcontainer.json.jinja index 88462b5c..0a1f8fea 100644 --- a/template/.devcontainer/prebuild/.devcontainer/devcontainer.json +++ b/template/.devcontainer/prebuild/.devcontainer/devcontainer.json.jinja @@ -3,7 +3,7 @@ "args": { "PYTHON_VERSION": "${localEnv:PYTHON_VERSION}" }, - "cacheFrom": "ghcr.io/serious-scaffold/ss-python:dev-py${localEnv:PYTHON_VERSION}", + "cacheFrom": "{{ container_registry_host }}/{{ repo_namespace }}/{{ repo_name }}:dev-py${localEnv:PYTHON_VERSION}", "context": "../../..", "dockerfile": "Dockerfile", "target": "dev" diff --git a/template/.vscode/settings.json b/template/.vscode/settings.json index 7250176e..73f2671b 100644 --- a/template/.vscode/settings.json +++ b/template/.vscode/settings.json @@ -128,6 +128,7 @@ "repo_host_type", "repo_host", "page_host", + "container_registry_host", "ci", "repo_namespace", "repo_name",