Skip to content

Commit

Permalink
ci: Publish both dev and prod containers when release. (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
huxuan authored Feb 1, 2024
1 parent e1b77b9 commit 48cd057
Show file tree
Hide file tree
Showing 19 changed files with 278 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ FROM dev as build
# Copy necessary files for build.
COPY pyproject.toml pdm.lock README.md /workspace/
COPY src/ /workspace/src
COPY .git/ /workspace/.git

# Install dependencies and project into the local packages directory.
WORKDIR /workspace
RUN mkdir __pypackages__ && pdm sync --prod --no-editable
ARG PDM_BUILD_SCM_VERSION=0.0.0
RUN mkdir __pypackages__ && PDM_BUILD_SCM_VERSION=${PDM_BUILD_SCM_VERSION} pdm sync --prod --no-editable

########################################################################################
# Prod image is used for deployment and distribution.
Expand All @@ -70,4 +70,4 @@ COPY --from=build /workspace/__pypackages__/${PYTHON_VERSION}/lib /workspace/pkg
COPY --from=build /workspace/__pypackages__/${PYTHON_VERSION}/bin/* /usr/local/bin/

# Set command to run the cli by default.
CMD ["ss-python-cli"]
ENTRYPOINT ["ss-python-cli"]
11 changes: 0 additions & 11 deletions .devcontainer/prebuild/.devcontainer/devcontainer.json

This file was deleted.

42 changes: 0 additions & 42 deletions .github/workflows/devcontainer.yml

This file was deleted.

53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,59 @@ jobs:
with:
body_path: release-notes.md
prerelease: ${{ steps.prerelease.outputs.is_prerelease }}
container-publish:
needs: release-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 }}
ghcr.io/${{ github.repository }}:dev-py${{ matrix.python-version }}-${{ github.ref_name }}
target: dev
- name: Build and push prod container
env:
SOURCE_DATE_EPOCH: 0
uses: docker/build-push-action@v5
with:
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 }}
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 }}
target: prod
strategy:
matrix:
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
package-publish:
needs: release-publish
runs-on: ubuntu-latest
Expand Down
30 changes: 0 additions & 30 deletions .gitlab/workflows/devcontainer.yml

This file was deleted.

48 changes: 48 additions & 0 deletions .gitlab/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,54 @@ release-publish:
script:
- echo "Running the release job."
stage: release
container-publish:
image: docker:latest
needs:
- release-publish
parallel:
matrix:
- PYTHON_VERSION:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
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]*)?)?$/
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
- |
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} \
--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} \
--target prod
services:
- docker:dind
stage: release
variables:
DOCKER_TLS_CERTDIR: /certs
PYTHON_VERSION: ${PYTHON_VERSION}
SOURCE_DATE_EPOCH: 0
package-publish:
needs:
- release-publish
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"pathjoin",
"pipenv",
"pipx",
"prebuild",
"pycache",
"pydantic",
"pyproject",
Expand Down Expand Up @@ -141,6 +140,7 @@
"id-token",
"pages-build",
"release-publish",
"container-publish",
"package-publish",
"pages",
"3.8",
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ changelog:

# Generate release notes from changelog.
release-notes:
pdm run $(PDM_GLOBAL) git-changelog --input $(CHANGELOG_PATH) --release-notes
git-changelog --input $(CHANGELOG_PATH) --release-notes

# Build documentation only from src.
doc-gen:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 Prebuild](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: 0 additions & 1 deletion includes/variable.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
[% 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 Prebuild](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
Expand Up @@ -46,11 +46,11 @@ FROM dev as build
# Copy necessary files for build.
COPY pyproject.toml pdm.lock README.md /workspace/
COPY src/ /workspace/src
COPY .git/ /workspace/.git

# Install dependencies and project into the local packages directory.
WORKDIR /workspace
RUN mkdir __pypackages__ && pdm sync --prod --no-editable
ARG PDM_BUILD_SCM_VERSION=0.0.0
RUN mkdir __pypackages__ && PDM_BUILD_SCM_VERSION=${PDM_BUILD_SCM_VERSION} pdm sync --prod --no-editable

########################################################################################
# Prod image is used for deployment and distribution.
Expand All @@ -70,4 +70,4 @@ COPY --from=build /workspace/__pypackages__/${PYTHON_VERSION}/lib /workspace/pkg
COPY --from=build /workspace/__pypackages__/${PYTHON_VERSION}/bin/* /usr/local/bin/

# Set command to run the cli by default.
CMD ["ss-python-cli"]
ENTRYPOINT ["{{ package_name }}-cli"]

This file was deleted.

2 changes: 1 addition & 1 deletion template/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"pathjoin",
"pipenv",
"pipx",
"prebuild",
"pycache",
"pydantic",
"pyproject",
Expand Down Expand Up @@ -141,6 +140,7 @@
"id-token",
"pages-build",
"release-publish",
"container-publish",
"package-publish",
"pages",
"3.8",
Expand Down
2 changes: 1 addition & 1 deletion template/Makefile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ changelog:

# Generate release notes from changelog.
release-notes:
pdm run $(PDM_GLOBAL) git-changelog --input $(CHANGELOG_PATH) --release-notes
git-changelog --input $(CHANGELOG_PATH) --release-notes

# Build documentation only from src.
doc-gen:
Expand Down

This file was deleted.

Loading

0 comments on commit 48cd057

Please sign in to comment.