From beca870f42fd8bd7aea360ed71c3e02363238ea1 Mon Sep 17 00:00:00 2001 From: ayazabbas <30928485+ayazabbas@users.noreply.github.com> Date: Tue, 7 May 2024 11:25:42 +0100 Subject: [PATCH] switch docker registry to ghcr (#61) --- .github/workflows/build-and-push-image.yaml | 71 +++++++++++++++++++++ .github/workflows/ci.yaml | 57 ----------------- pyproject.toml | 2 +- 3 files changed, 72 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/build-and-push-image.yaml delete mode 100644 .github/workflows/ci.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..2a90159 --- /dev/null +++ b/.github/workflows/build-and-push-image.yaml @@ -0,0 +1,71 @@ +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: ./.github/actions/python-poetry + - uses: pre-commit/action@v2.0.3 + + run-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/python-poetry + - run: poetry run pytest + env: + TEST_MODE: "1" + + build-and-push: + permissions: + contents: read + packages: write + runs-on: ubuntu-latest + needs: [pre-commit, run-tests] + 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/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index 4b91015..0000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: CI -on: - push: - branches: - - "main" - tags: - - v* - pull_request: - branches: - - "main" -jobs: - pre-commit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/python-poetry - - uses: pre-commit/action@v2.0.3 - run-tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/python-poetry - - run: poetry run pytest - env: - TEST_MODE: "1" - build-and-push-ecr: - runs-on: ubuntu-latest - needs: [pre-commit, run-tests] - 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/observer:${{ steps.image_tag.outputs.value }} diff --git a/pyproject.toml b/pyproject.toml index 13205e4..12478a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ ignore_missing_imports = true [tool.poetry] name = "pyth-observer" -version = "0.1.14" +version = "0.1.15" description = "Alerts and stuff" authors = [] readme = "README.md"