From a9765a6ac39d5fb802fe6b3ac1c919d95dcc0253 Mon Sep 17 00:00:00 2001 From: Ayaz Abbas Date: Tue, 7 May 2024 11:44:13 +0100 Subject: [PATCH 1/2] switch docker registry to ghcr --- .github/workflows/build-and-push-image.yaml | 54 +++++++++++++++++++++ .github/workflows/image-push.yaml | 43 ---------------- pyproject.toml | 2 +- 3 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/build-and-push-image.yaml delete mode 100644 .github/workflows/image-push.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..249da9a --- /dev/null +++ b/.github/workflows/build-and-push-image.yaml @@ -0,0 +1,54 @@ +name: Docker Image Build +on: + push: + tags: + - v* + pull_request: + branches: ["main"] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + permissions: + contents: read + packages: write + runs-on: ubuntu-latest + 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/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" From d2a32f70054c941faeef6561151d71f67ec91a62 Mon Sep 17 00:00:00 2001 From: Ayaz Abbas Date: Tue, 7 May 2024 11:48:49 +0100 Subject: [PATCH 2/2] move pre-commit and tests to the same workflow --- .github/workflows/build-and-push-image.yaml | 33 +++++++++++++++++++++ .github/workflows/poetry.yaml | 21 ------------- .github/workflows/pre-commit.yaml | 23 -------------- 3 files changed, 33 insertions(+), 44 deletions(-) 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 index 249da9a..6efa554 100644 --- a/.github/workflows/build-and-push-image.yaml +++ b/.github/workflows/build-and-push-image.yaml @@ -11,11 +11,44 @@ env: 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 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