diff --git a/.github/workflows/agent-build.yml b/.github/workflows/agent-build.yml deleted file mode 100644 index 3f89296..0000000 --- a/.github/workflows/agent-build.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: CI - -on: - push: - branches: - - 'feature/**' - - 'v[0-9]+.[0-9]+' - pull_request: - branches: - - main - - 'feature/**' - - 'v[0-9]+.[0-9]+' - -env: - GO_VERSION: 1.22.1 - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} - cancel-in-progress: true - -jobs: - golangci: - strategy: - fail-fast: false - name: Build and Push - runs-on: ubuntu-latest - steps: - - name: Checkout repo - uses: actions/checkout@v3 - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: ${{ env.GO_VERSION }} - - name: Docker login - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Docker Build - run: | - make agent-image - - name: Docker Push - run: | - make agent-push - - - \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..18d982b --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,78 @@ +name: Telescope Docker + +# Cancel workflow if there is a new change to the branch. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +on: + push: + branches: [main] + tags: + - "*" + merge_group: + pull_request: + branches: + - main + - 'feature/**' + - 'v[0-9]+.[0-9]+' + # This needs to be declared explicitly so that the job is actually + # run when moved out of draft. + types: [opened, synchronize, reopened, ready_for_review] + + +jobs: + build-and-push-docker-image: + # This is done to limit the runner cost. + # if: github.event.pull_request.draft == false + name: Build images and push to docker hub + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: List cached docker images + run: docker image ls + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: all + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Docker Meta + id: meta + uses: docker/metadata-action@v5 + with: + images: blockopsnetwork/telescope + flavor: | + latest=false + tags: | + type=raw,value={{date 'YYYY-MM-DD'}}-{{sha}} + type=ref,event=tag + type=edge + + - name: free disk space + run: | + make cleanup-action + + - name: Build telescope image and push to DockerHub + uses: docker/build-push-action@v6 + with: + file: ./cmd/agent/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }} + # Compile Docker image only for AMD64 for a regular PR to save some CI time. + platforms: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && 'linux/amd64,linux/arm64' || 'linux/amd64' }} + + diff --git a/.github/workflows/tag-latest-image.yml b/.github/workflows/tag-latest-image.yml new file mode 100644 index 0000000..9bc4fc7 --- /dev/null +++ b/.github/workflows/tag-latest-image.yml @@ -0,0 +1,50 @@ +name: Docker Latest tag For Releases + +on: + workflow_dispatch: + inputs: + tag: + description: 'Tag of the base image to use' + required: true + type: string + new_tag: + description: 'New tag to use' + default: 'latest' + required: true + type: string + dry_run: + description: "Don't push the tag to DockerHub" + required: true + type: boolean + default: false + +jobs: + tag-docker-image: + name: Retag image and push to DockerHub + runs-on: ubuntu-latest + steps: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: all + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Create builder + run: docker buildx create --name mybuilder --use + + - name: Inspect builder + run: docker buildx inspect --bootstrap + + - name: Pull the original image + run: docker pull blockopsnetwork/telescope:${{ github.event.inputs.tag }} + + - name: Create new multi-arch image with new tag + run: docker buildx imagetools create --tag blockopsnetwork/telescope:${{ github.event.inputs.new_tag }} blockopsnetwork/telescope:${{ github.event.inputs.tag }} diff --git a/Makefile b/Makefile index f0edcea..3cd0554 100644 --- a/Makefile +++ b/Makefile @@ -196,4 +196,8 @@ ifeq ($(USE_CONTAINER),1) $(RERUN_IN_CONTAINER) else go generate ./docs -endif \ No newline at end of file +endif + +.PHONY: cleanup-action +cleanup-action: + bash ./script/action-ci-clean-up.bash diff --git a/cmd/agent/Dockerfile b/cmd/agent/Dockerfile index 791d9be..2aed68a 100644 --- a/cmd/agent/Dockerfile +++ b/cmd/agent/Dockerfile @@ -46,7 +46,7 @@ RUN <