Skip to content

Commit

Permalink
ci: Fix GitLab Pages deploy, revert devconatiner workflow for bootstr…
Browse files Browse the repository at this point in the history
…ap. (#298)
  • Loading branch information
huxuan authored Feb 1, 2024
1 parent 48cd057 commit 38fd1cc
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: DevContainer
concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
dev-container-publish:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.actor }}
- name: Build and push dev container
env:
SOURCE_DATE_EPOCH: 0
uses: docker/build-push-action@v5
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
file: .devcontainer/Dockerfile
provenance: false
push: true
tags: |
ghcr.io/${{ github.repository }}:dev-py${{ matrix.python-version }}
target: dev
strategy:
matrix:
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
on:
push:
branches:
- main
paths:
- .devcontainer/Dockerfile
workflow_dispatch: null
37 changes: 37 additions & 0 deletions .gitlab/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
dev-container-publish:
image: docker:latest
parallel:
matrix:
- PYTHON_VERSION:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
rules:
- changes:
- .devcontainer/Dockerfile
if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- docker context create builder
- docker buildx create builder --name container --driver docker-container --use
- docker buildx inspect --bootstrap --builder container
- |
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 \
--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} \
--target dev
services:
- docker:dind
stage: build
variables:
DOCKER_TLS_CERTDIR: /certs
PYTHON_VERSION: ${PYTHON_VERSION}
SOURCE_DATE_EPOCH: 0
1 change: 1 addition & 0 deletions .gitlab/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pages:
paths:
- public
needs:
- pages-build
- release-publish
rules:
- if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ A Python project template covering the entire development lifecycle with various

[![CI](https://github.com/serious-scaffold/ss-python/actions/workflows/ci.yml/badge.svg)](https://github.com/serious-scaffold/ss-python/actions/workflows/ci.yml)
[![Release](https://github.com/serious-scaffold/ss-python/actions/workflows/release.yml/badge.svg)](https://github.com/serious-scaffold/ss-python/actions/workflows/release.yml)
[![DevContainer](https://github.com/serious-scaffold/ss-python/actions/workflows/devcontainer.yml/badge.svg)](https://github.com/serious-scaffold/ss-python/actions/workflows/devcontainer.yml)
[![Coverage](https://img.shields.io/endpoint?url=https://serious-scaffold.github.io/ss-python/_static/badges/coverage.json)](https://serious-scaffold.github.io/ss-python/reports/coverage)
[![PyPI](https://img.shields.io/pypi/v/ss-python)](https://pypi.org/project/ss-python/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ss-python)](https://pypi.org/project/ss-python/)
Expand Down
1 change: 1 addition & 0 deletions includes/variable.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
[% if repo_host_type == 'github.com' -%]
[![CI](https://{{ repo_url() }}/actions/workflows/ci.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/ci.yml)
[![Release](https://{{ repo_url() }}/actions/workflows/release.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/release.yml)
[![DevContainer](https://{{ repo_url() }}/actions/workflows/devcontainer.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/devcontainer.yml)
[%- elif repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' -%]
[![pipeline status](https://{{ repo_url() }}/badges/main/pipeline.svg)](https://{{ repo_url() }}/-/commits/main)
[%- endif %]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[% from pathjoin("includes", "version_compare.jinja") import version_between -%]
name: DevContainer
concurrency:
cancel-in-progress: true
group: {{ '${{ github.workflow }}-${{ github.ref }}' }}
jobs:
dev-container-publish:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
password: {{ '${{ secrets.GITHUB_TOKEN }}' }}
registry: ghcr.io
username: {{ '${{ github.actor }}' }}
- name: Build and push dev container
env:
SOURCE_DATE_EPOCH: 0
uses: docker/build-push-action@v5
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
file: .devcontainer/Dockerfile
provenance: false
push: true
tags: |
ghcr.io/{{ '${{ github.repository }}' }}:dev-py{{ '${{ matrix.python-version }}' }}
target: dev
strategy:
matrix:
python-version:
[%- if version_between("3.8", min_py, max_py) %]
- '3.8'
[%- endif %]
[%- if version_between("3.9", min_py, max_py) %]
- '3.9'
[%- endif %]
[%- if version_between("3.10", min_py, max_py) %]
- '3.10'
[%- endif %]
[%- if version_between("3.11", min_py, max_py) %]
- '3.11'
[%- endif %]
[%- if version_between("3.12", min_py, max_py) %]
- '3.12'
[%- endif %]
on:
push:
branches:
- main
paths:
- .devcontainer/Dockerfile
workflow_dispatch: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[% from pathjoin("includes", "version_compare.jinja") import version_between -%]
dev-container-publish:
image: docker:latest
parallel:
matrix:
- PYTHON_VERSION:
[%- if version_between("3.8", min_py, max_py) %]
- '3.8'
[%- endif %]
[%- if version_between("3.9", min_py, max_py) %]
- '3.9'
[%- endif %]
[%- if version_between("3.10", min_py, max_py) %]
- '3.10'
[%- endif %]
[%- if version_between("3.11", min_py, max_py) %]
- '3.11'
[%- endif %]
[%- if version_between("3.12", min_py, max_py) %]
- '3.12'
[%- endif %]
rules:
- changes:
- .devcontainer/Dockerfile
if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- docker context create builder
- docker buildx create builder --name container --driver docker-container --use
- docker buildx inspect --bootstrap --builder container
- |
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 \
--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} \
--target dev
services:
- docker:dind
stage: build
variables:
DOCKER_TLS_CERTDIR: /certs
PYTHON_VERSION: ${PYTHON_VERSION}
SOURCE_DATE_EPOCH: 0
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pages:
paths:
- public
needs:
- pages-build
- release-publish
rules:
- if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/
Expand Down

0 comments on commit 38fd1cc

Please sign in to comment.