From b359c0408a4751c7d35acf6e1ae424c8662a937d Mon Sep 17 00:00:00 2001 From: ayazabbas <30928485+ayazabbas@users.noreply.github.com> Date: Tue, 7 May 2024 14:01:51 +0100 Subject: [PATCH] switch docker registry to ghcr (#27) * switch docker registry to ghcr * move pre-commit and tests to the same workflow --- .github/workflows/build-and-push-image.yaml | 87 +++++++++++++++++++++ .github/workflows/image-push.yaml | 43 ---------- .github/workflows/poetry.yaml | 21 ----- .github/workflows/pre-commit.yaml | 23 ------ pyproject.toml | 2 +- 5 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/build-and-push-image.yaml delete mode 100644 .github/workflows/image-push.yaml delete mode 100644 .github/workflows/poetry.yaml delete mode 100644 .github/workflows/pre-commit.yaml diff --git a/.github/workflows/build-and-push-image.yaml b/.github/workflows/build-and-push-image.yaml new file mode 100644 index 0000000..6efa554 --- /dev/null +++ b/.github/workflows/build-and-push-image.yaml @@ -0,0 +1,87 @@ +name: Docker Image Build +on: + push: + tags: + - v* + pull_request: + branches: ["main"] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Run image + uses: abatilo/actions-poetry@v2 + with: + poetry-version: '1.3.2' + - name: Install dependencies + run: poetry install + - name: Run pre-commit + run: poetry run pre-commit run --all-files + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Run image + uses: abatilo/actions-poetry@v2 + with: + poetry-version: '1.3.2' + - name: Install dependencies + run: poetry install + - name: Run tests + run: poetry run pytest + + build-and-push: + permissions: + contents: read + packages: write + runs-on: ubuntu-latest + needs: [pre-commit, test] + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + # Set image tag to git tag, or commit hash for pull request + - name: Set IMAGE_TAG + run: | + if [ "${{ github.event_name }}" == "push" ]; then + echo "IMAGE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + else + echo "IMAGE_TAG=${{ github.sha }}" >> $GITHUB_ENV + fi + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=${{ env.IMAGE_TAG }} + type=raw,value=${{ github.sha }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/image-push.yaml b/.github/workflows/image-push.yaml deleted file mode 100644 index 1a76ca3..0000000 --- a/.github/workflows/image-push.yaml +++ /dev/null @@ -1,43 +0,0 @@ -name: Build and Push Example Publisher Image -on: - push: - tags: - - v* - workflow_dispatch: - inputs: - dispatch_description: - description: "Dispatch description" - required: true - type: string -jobs: - example-publisher-push-image: - runs-on: ubuntu-latest - permissions: - id-token: write - contents: read - steps: - - uses: actions/checkout@v2 - - uses: aws-actions/configure-aws-credentials@8a84b07f2009032ade05a88a28750d733cc30db1 - with: - role-to-assume: arn:aws:iam::192824654885:role/github-actions-ecr - aws-region: eu-west-2 - - uses: docker/login-action@v2 - with: - registry: public.ecr.aws - env: - AWS_REGION: us-east-1 - - run: docker context create builders - - uses: docker/setup-buildx-action@v2 - with: - version: latest - endpoint: builders - - uses: haya14busa/action-cond@v1 - id: image_tag - with: - cond: ${{ startsWith(github.ref, 'refs/tags/') }} - if_true: ${{ github.ref_name }} - if_false: ${{ github.sha }} - - uses: docker/build-push-action@v2 - with: - push: true - tags: public.ecr.aws/pyth-network/example-publisher:${{ steps.image_tag.outputs.value }} diff --git a/.github/workflows/poetry.yaml b/.github/workflows/poetry.yaml deleted file mode 100644 index 8a136f1..0000000 --- a/.github/workflows/poetry.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Python tests -on: - pull_request: - push: - branches: [main] -jobs: - ci: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Run image - uses: abatilo/actions-poetry@v2 - with: - poetry-version: '1.3.2' - - name: Install dependencies - run: poetry install - - name: Run tests - run: poetry run pytest diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml deleted file mode 100644 index ec30efb..0000000 --- a/.github/workflows/pre-commit.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: Pre-commit - -on: - pull_request: - push: - branches: [main] - -jobs: - pre-commit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Run image - uses: abatilo/actions-poetry@v2 - with: - poetry-version: '1.3.2' - - name: Install dependencies - run: poetry install - - name: Run pre-commit - run: poetry run pre-commit run --all-files diff --git a/pyproject.toml b/pyproject.toml index 19aa8b3..020b722 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "example-publisher" -version = "1.1.0" +version = "1.1.1" description = "" authors = [] license = "Apache-2"