-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from br3ndonland/ghcr
Build Docker image and push to GHCR
- Loading branch information
Showing
4 changed files
with
224 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
|
||
name: 🏗️ | ||
|
||
on: # yamllint disable-line rule:truthy | ||
pull_request: | ||
push: | ||
branches: ["release/*", "unstable/*"] | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: Docker image tag | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
smoke-test: | ||
uses: ./.github/workflows/reusable-smoke-test.yml | ||
build-and-push: | ||
if: github.event_name != 'pull_request' | ||
runs-on: ubuntu-latest | ||
needs: | ||
- smoke-test | ||
timeout-minutes: 10 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build Docker image | ||
run: | | ||
DOCKER_TAG="${DOCKER_TAG/'/'/'-'}" | ||
DOCKER_TAG_MAJOR=$(echo "$DOCKER_TAG" | cut -d '.' -f 1) | ||
DOCKER_TAG_MAJOR_MINOR=$(echo "$DOCKER_TAG" | cut -d '.' -f 1-2) | ||
IMAGE="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG}" | ||
IMAGE_MAJOR="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG_MAJOR}" | ||
IMAGE_MAJOR_MINOR="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG_MAJOR_MINOR}" | ||
echo "IMAGE=$IMAGE" >>"$GITHUB_ENV" | ||
echo "IMAGE_MAJOR=$IMAGE_MAJOR" >>"$GITHUB_ENV" | ||
echo "IMAGE_MAJOR_MINOR=$IMAGE_MAJOR_MINOR" >>"$GITHUB_ENV" | ||
docker build . \ | ||
--build-arg BUILDKIT_INLINE_CACHE=1 \ | ||
--cache-from $IMAGE \ | ||
--tag $IMAGE | ||
docker tag $IMAGE $IMAGE_MAJOR | ||
docker tag $IMAGE $IMAGE_MAJOR_MINOR | ||
env: | ||
DOCKER_TAG: ${{ inputs.tag || github.ref_name }} | ||
- name: Log in to GHCR | ||
run: >- | ||
echo ${{ secrets.GITHUB_TOKEN }} | | ||
docker login ghcr.io -u $GITHUB_ACTOR --password-stdin | ||
- name: Push Docker image to GHCR | ||
run: | | ||
docker push $IMAGE | ||
docker push $IMAGE_MAJOR | ||
docker push $IMAGE_MAJOR_MINOR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import json | ||
import os | ||
import pathlib | ||
|
||
DESCRIPTION = 'description' | ||
REQUIRED = 'required' | ||
|
||
REF = os.environ['REF'] | ||
REPO = os.environ['REPO'] | ||
REPO_ID = os.environ['REPO_ID'] | ||
REPO_ID_GH_ACTION = '178055147' | ||
|
||
|
||
def set_image(ref: str, repo: str, repo_id: str) -> str: | ||
if repo_id == REPO_ID_GH_ACTION: | ||
return '../../../Dockerfile' | ||
docker_ref = ref.replace('/', '-') | ||
return f'docker://ghcr.io/{repo}:{docker_ref}' | ||
|
||
|
||
image = set_image(REF, REPO, REPO_ID) | ||
|
||
action = { | ||
'name': '🏃', | ||
DESCRIPTION: ( | ||
'Run Docker container to upload Python distribution packages to PyPI' | ||
), | ||
'inputs': { | ||
'user': {DESCRIPTION: 'PyPI user', REQUIRED: False}, | ||
'password': { | ||
DESCRIPTION: 'Password for your PyPI user or an access token', | ||
REQUIRED: False, | ||
}, | ||
'repository-url': { | ||
DESCRIPTION: 'The repository URL to use', | ||
REQUIRED: False, | ||
}, | ||
'packages-dir': { | ||
DESCRIPTION: 'The target directory for distribution', | ||
REQUIRED: False, | ||
}, | ||
'verify-metadata': { | ||
DESCRIPTION: 'Check metadata before uploading', | ||
REQUIRED: False, | ||
}, | ||
'skip-existing': { | ||
DESCRIPTION: ( | ||
'Do not fail if a Python package distribution' | ||
' exists in the target package index' | ||
), | ||
REQUIRED: False, | ||
}, | ||
'verbose': {DESCRIPTION: 'Show verbose output.', REQUIRED: False}, | ||
'print-hash': { | ||
DESCRIPTION: 'Show hash values of files to be uploaded', | ||
REQUIRED: False, | ||
}, | ||
'attestations': { | ||
DESCRIPTION: ( | ||
'[EXPERIMENTAL]' | ||
' Enable experimental support for PEP 740 attestations.' | ||
' Only works with PyPI and TestPyPI via Trusted Publishing.' | ||
), | ||
REQUIRED: False, | ||
}, | ||
}, | ||
'runs': { | ||
'using': 'docker', | ||
'image': image, | ||
}, | ||
} | ||
|
||
action_path = pathlib.Path('.github/actions/run-docker-container/action.yml') | ||
action_path.parent.mkdir(parents=True, exist_ok=True) | ||
action_path.write_text(json.dumps(action, ensure_ascii=False), encoding='utf-8') |