Skip to content

Commit

Permalink
feat: release docker images using github ci, not gitlab (#1636)
Browse files Browse the repository at this point in the history
* feat: release using github ci

* chore: base on pyquil version, not repository tag

* fix: use correct output setup and fully tested

* fix: rc vs latest branch pushing from env vars not tag formatters

* chore: add testing dockerfile
  • Loading branch information
jselig-rigetti committed Aug 28, 2023
1 parent 76631f4 commit 9bd4a92
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 63 deletions.
70 changes: 68 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,84 @@ on:
workflow_dispatch:
description: "Manually publish release"

env:
# Only used ephemerally for validating image
DOCKER_TEST_TAG: "${{ env.DOCKER_IMAGE_NAME }}:test"

jobs:
build-publish:
name: Build and Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: snok/install-poetry@v1
with:
virtualenvs-in-project: true
- name: "Build"
run: |
. scripts/ci_install_deps
poetry build --no-interaction
- name: "Publish"
- id: publish
name: "Publish"
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}
poetry publish
export PYQUIL_TAG_VERSION=$(poetry version --short)
export PYQUIL_TAG_LATEST=$([[ "$PYQUIL_TAG_VERSION" =~ ^[0-9]+[.][0-9]+[.][0-9]+$ ]] && echo latest || echo)
export PYQUIL_TAG_RC=$([[ "$PYQUIL_TAG_VERSION" =~ ^[0-9]+[.][0-9]+[.][0-9]+-rc[.][0-9]+$ ]] && echo rc || echo)
echo "PYQUIL_TAG_VERSION=$PYQUIL_TAG_VERSION" >> "$GITHUB_OUTPUT"
echo "PYQUIL_TAG_LATEST=$PYQUIL_TAG_LATEST" >> "$GITHUB_OUTPUT"
echo "PYQUIL_TAG_RC=$PYQUIL_TAG_RC" >> "$GITHUB_OUTPUT"
outputs:
PYQUIL_TAG_VERSION: ${{ steps.publish.outputs.PYQUIL_TAG_VERSION }}
PYQUIL_TAG_LATEST: ${{ steps.publish.outputs.PYQUIL_TAG_LATEST }}
PYQUIL_TAG_RC: ${{ steps.publish.outputs.PYQUIL_TAG_RC }}
docker-publish:
name: Docker Publish
runs-on: ubuntu-latest
needs: build-publish
env:
PYQUIL_TAG_VERSION: ${{ needs.build-publish.outputs.PYQUIL_TAG_VERSION }}
PYQUIL_TAG_LATEST: ${{ needs.build-publish.outputs.PYQUIL_TAG_LATEST }}
PYQUIL_TAG_RC: ${{ needs.build-publish.outputs.PYQUIL_TAG_RC }}
steps:
# Determine the tags to publish based on the release tag
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.DOCKER_IMAGE_NAME }}
tags: |
type=raw,value=${{ env.PYQUIL_TAG_VERSION }}
type=raw,value=${{ env.PYQUIL_TAG_LATEST }},enable=${{ env.PYQUIL_TAG_LATEST != '' }}
type=raw,value=${{ env.PYQUIL_TAG_RC }},enable=${{ env.PYQUIL_TAG_RC != '' }}
# Checkout is needed to use the path context: .
- name: Checkout
uses: actions/checkout@v3
- name: Build and Test
uses: docker/build-push-action@v4
with:
context: .
load: true
tags: ${{ env.DOCKER_TEST_TAG }}
build-args: |
pyquil_version=${{ env.PYQUIL_TAG_VERSION }}
- name: Test Image
run: |
docker run --rm ${{ env.DOCKER_TEST_TAG }} python -c "from pyquil import get_qc"
# Build and publish the image
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and Push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
pyquil_version=${{ env.PYQUIL_TAG_VERSION }}
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,34 @@ jobs:
thresholdNew: 0.9
token: ${{ secrets.PAT }}

check-docker-image:
name: Check types
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'
- uses: actions/cache@v2
with:
path: .venv
key: poetry-${{ hashFiles('poetry.lock') }}
- name: Check types
run: |
sudo apt update
pip wheel . -w wheels
- name: Build and Test
uses: docker/build-push-action@v4
with:
file: Dockerfile.test
context: .
load: true
tags: test
- name: Test Image
run: |
docker run --rm test python -c "from pyquil import get_qc"
test-e2e:
name: Test e2e QVM
runs-on: ubuntu-latest
Expand Down
59 changes: 0 additions & 59 deletions .gitlab-ci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# use multi-stage builds to independently pull dependency versions
ARG quilc_version=1.20.0
ARG qvm_version=1.17.1
ARG python_version=3.7
ARG python_version=3.8

# use multi-stage builds to independently pull dependency versions
FROM rigetti/quilc:$quilc_version as quilc
Expand Down
33 changes: 33 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# use multi-stage builds to independently pull dependency versions
ARG quilc_version=1.20.0
ARG qvm_version=1.17.1
ARG python_version=3.8

# use multi-stage builds to independently pull dependency versions
FROM rigetti/quilc:$quilc_version as quilc
FROM rigetti/qvm:$qvm_version as qvm
FROM python:$python_version-buster

# copy over the pre-built quilc binary from the first build stage
COPY --from=quilc /src/quilc/quilc /src/quilc/quilc

# copy over the pre-built qvm binary from the second build stage
COPY --from=qvm /src/qvm/qvm /src/qvm/qvm

# install the missing apt packages that aren't copied over
RUN apt-get update && apt-get -yq dist-upgrade && \
apt-get install --no-install-recommends -yq \
git libblas-dev libffi-dev liblapack-dev libzmq3-dev && \
rm -rf /var/lib/apt/lists/*

# install ipython
RUN pip install --no-cache-dir ipython

# install pyquil from local wheel
COPY ./wheels /src/wheels
RUN pip install /src/wheels/pyquil-*.whl

# use an entrypoint script to add startup commands (qvm & quilc server spinup)
COPY ./entrypoint.sh /src/pyquil/entrypoint.sh
ENTRYPOINT ["/src/pyquil/entrypoint.sh"]
CMD ["ipython"]
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ license = "Apache-2.0"
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Operating System :: OS Independent",
Expand Down

0 comments on commit 9bd4a92

Please sign in to comment.