Skip to content

Commit

Permalink
Update docker build script to use unique version generated from relea…
Browse files Browse the repository at this point in the history
…ser.py
  • Loading branch information
FirelightFlagboy committed Mar 6, 2024
1 parent 28f910b commit 64a2691
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/docker-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ jobs:

- name: Get current version
id: version
run: |
sed -n 's/^.*Tool.Parsec: "\(.*\)",$/current=\1/p' misc/version_updater.py | tee $GITHUB_OUTPUT
run: >-
PYTHONPATH=. python3
misc/releaser.py version --uniq-dev
| tee -a $GITHUB_OUTPUT
timeout-minutes: 1

- name: Generate build metadata
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
Expand All @@ -57,7 +60,8 @@ jobs:
tags: |
type=semver,pattern={{ version }}
type=semver,pattern={{ major }}.{{ minor }}
type=raw,value=${{ steps.version.outputs.current }}+{{ date 'YYYYMMDD' }}.sha.{{ sha }}
type=raw,value=${{ steps.version.outputs.docker }}
type=schedule,enable=${{ github.event_name == 'push' && github.ref_type == 'tag' && github.ref == 'refs/tags/nightly' && 'true' || 'false' }},pattern=nightly
flavor: |
latest=${{ github.event_name == 'push' && github.ref_type == 'tag' }}
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/docker-testbed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ jobs:

- name: Get current version
id: version
run: |
sed -n 's/^.*Tool.Parsec: "\(.*\)",$/current=\1/p' misc/version_updater.py | tee $GITHUB_OUTPUT
run: >-
PYTHONPATH=. python3
misc/releaser.py version --uniq-dev
| tee -a $GITHUB_OUTPUT
timeout-minutes: 1

- name: Generate build metadata
Expand All @@ -66,7 +68,7 @@ jobs:
images:
ghcr.io/scille/parsec-cloud/parsec-testbed-server
tags: |
type=raw,value=${{ steps.version.outputs.current }}+{{ date 'YYYYMMDD' }}.sha.{{ sha }}
type=raw,value=${{ steps.version.outputs.docker }}
flavor: |
latest=${{ github.event_name == 'workflow_dispatch' }}
Expand Down
9 changes: 9 additions & 0 deletions misc/releaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ def to_pep440(self) -> str:
def without_local(self) -> Version:
return self.evolve(local=None)

def docker_tag(self) -> str:
"""
Format the version into a docker tag.
A docker tag is human-readable identifier composed of [a-zA-Z0-9_.-]
https://docs.docker.com/reference/cli/docker/image/tag/
"""
return str(self).replace("+", ".")

def __repr__(self) -> str:
return f"Version(major={self.major}, minor={self.minor}, patch={self.patch}, prerelease={self.prerelease}, dev={self.dev}, local={self.local})"

Expand Down Expand Up @@ -782,6 +790,7 @@ def version_main(args: argparse.Namespace) -> None:
f"dev={version.dev or ''}",
f"local={version.local or ''}",
f"no_local={version.without_local()}",
f"docker={version.docker_tag()}",
]
)
)
Expand Down
6 changes: 1 addition & 5 deletions server/packaging/server/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ SCRIPTDIR=${SCRIPTDIR:=$(dirname "$(realpath -s "$0")")}
# Allow the user to overwrite `ROOTDIR` by exporting it beforehand.
ROOTDIR=${ROOTDIR:=$(realpath -s "$SCRIPTDIR/../../..")}

CURRENT_DATE=$(date --iso-8601)
CURRENT_VERSION=$(grep -o '^version = .*$' $ROOTDIR/server/pyproject.toml | sed 's/version = "\(.*\)"$/\1/' | tr '+' '.')
CURRENT_COMMIT_SHA=$(git rev-parse --short HEAD)

UNIQ_TAG="$CURRENT_DATE-$CURRENT_VERSION-$CURRENT_COMMIT_SHA"
UNIQ_TAG=$(PYTHONPATH=$ROOTDIR python $ROOTDIR/misc/releaser.py version --uniq-dev | sed -n 's/docker=\(.*\)$/\1/p')
# We use Github package repository to store our docker's container.
PREFIX=ghcr.io/scille/parsec-cloud
IMAGE_NAME=parsec-server
Expand Down
6 changes: 1 addition & 5 deletions server/packaging/testbed-server/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ SCRIPTDIR=${SCRIPTDIR:=$(dirname "$(realpath -s "$0")")}
# Allow the user to overwrite `ROOTDIR` by exporting it beforehand.
ROOTDIR=${ROOTDIR:=$(realpath -s "$SCRIPTDIR/../../..")}

CURRENT_DATE=$(date --iso-8601)
CURRENT_VERSION=$(grep -o '^version = .*$' $ROOTDIR/server/pyproject.toml | sed 's/version = "\(.*\)"$/\1/' | tr '+' '-' )
CURRENT_COMMIT_SHA=$(git rev-parse --short HEAD)

UNIQ_TAG="$CURRENT_VERSION.$CURRENT_DATE-sha.$CURRENT_COMMIT_SHA"
UNIQ_TAG=$(PYTHONPATH=$ROOTDIR python $ROOTDIR/misc/releaser.py version --uniq-dev | sed -n 's/docker=\(.*\)$/\1/p')
# We use Github package repository to store our docker's container.
PREFIX=ghcr.io/scille/parsec-cloud

Expand Down

0 comments on commit 64a2691

Please sign in to comment.