From 5caef0edc615a5be731de0f6eaefe0a08afd4a7f Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Mon, 29 Jan 2024 11:18:44 +0000 Subject: [PATCH] ci: Publish prod container when release. --- .../prebuild/.devcontainer/Dockerfile | 6 +-- .github/workflows/release.yml | 52 +++++++++++++++++++ .vscode/settings.json | 1 + Makefile | 2 +- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/.devcontainer/prebuild/.devcontainer/Dockerfile b/.devcontainer/prebuild/.devcontainer/Dockerfile index 694cd0c8..969444a3 100644 --- a/.devcontainer/prebuild/.devcontainer/Dockerfile +++ b/.devcontainer/prebuild/.devcontainer/Dockerfile @@ -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. @@ -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"] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 83f8dcb9..509e36fe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json index a0bfeb89..eb0052de 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -141,6 +141,7 @@ "id-token", "pages-build", "release-publish", + "container-publish", "package-publish", "pages", "3.8", diff --git a/Makefile b/Makefile index dee6a657..fa2ef7b3 100644 --- a/Makefile +++ b/Makefile @@ -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: