Skip to content

Commit

Permalink
ci: Publish prod container when release.
Browse files Browse the repository at this point in the history
  • Loading branch information
huxuan committed Jan 31, 2024
1 parent e1b77b9 commit 5caef0e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/prebuild/.devcontainer/Dockerfile
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"]
52 changes: 52 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,58 @@ 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/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 }}:dev-py${{ matrix.python-version }}
cache-to: type=inline
file: .devcontainer/prebuild/.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 }}:dev-py${{ matrix.python-version }}
file: .devcontainer/prebuild/.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
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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

0 comments on commit 5caef0e

Please sign in to comment.