Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build multi platform docker images #22

Merged
merged 32 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1ab870a
feat: build muilti platform docker images
segunjkf Jun 21, 2024
0919a14
wip: test build on ci
segunjkf Jun 21, 2024
58c9cfd
fix: try fixing failing build
segunjkf Jun 21, 2024
8fe5279
fix: docker building path error
segunjkf Jun 21, 2024
ff34d3c
wip: test push image
segunjkf Jun 21, 2024
31f5b38
wip: test build multiplatform on all builds
segunjkf Jun 21, 2024
79d2a8f
wip: test build multiplatform on all builds
segunjkf Jun 21, 2024
e9d0a93
wip: test push new multi platform docker image
segunjkf Jun 24, 2024
d69edcf
wip: fixing error platform specifications
segunjkf Jun 24, 2024
c4d9d9c
wip: try build for only one platform
segunjkf Jun 24, 2024
a4d762b
wip: try build for only one platform
segunjkf Jun 24, 2024
6ef39b4
wip: try build for only one platform
segunjkf Jun 24, 2024
8114ecc
build for arm64 and amd64
segunjkf Jun 24, 2024
7e17ecd
wip : try clean up builds
segunjkf Jun 24, 2024
623f905
wip : trying freeing up storage
segunjkf Jun 24, 2024
fff6135
wip: try the unthinkable
segunjkf Jun 24, 2024
9d3e31f
wip: add clean up method
segunjkf Jun 24, 2024
58f4e5a
nits: push image only on tag or merge to main
segunjkf Jun 24, 2024
ec6aca7
nits: test retag
segunjkf Jun 24, 2024
a123c90
nits: test retag
segunjkf Jun 24, 2024
492821d
nits: test retag
segunjkf Jun 24, 2024
a29d448
nits: test retag for all arch
segunjkf Jun 24, 2024
26e3f5a
nits: test retag for all arch
segunjkf Jun 24, 2024
78da7c0
nits: test retag for all arch
segunjkf Jun 24, 2024
99bfbf9
nits: test retag for all arch
segunjkf Jun 24, 2024
7aedf59
nits: test retag for all arch
segunjkf Jun 24, 2024
326afe2
nits: test retag for all arch
segunjkf Jun 24, 2024
d4e6f61
nits: test retag for all arch
segunjkf Jun 24, 2024
a3f69aa
nits: dont want docker build on draft to same cost
segunjkf Jun 24, 2024
43391ad
nits: pr review changes
segunjkf Jun 24, 2024
a71a4bc
chore: remove old docker build workflow
segunjkf Jun 24, 2024
93a1716
Merge branch 'main' into segun/multiplaform-docker-build
segunjkf Jun 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions .github/workflows/agent-build.yml

This file was deleted.

78 changes: 78 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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
haroldsphinx marked this conversation as resolved.
Show resolved Hide resolved
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' }}


50 changes: 50 additions & 0 deletions .github/workflows/tag-latest-image.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,8 @@ ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
go generate ./docs
endif
endif

.PHONY: cleanup-action
cleanup-action:
bash ./script/action-ci-clean-up.bash
2 changes: 1 addition & 1 deletion cmd/agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN <<EOF
EOF

COPY --from=build /src/agent/build/agent /bin/agent
COPY cmd/agent/agent-local-config.yaml /etc/agent/agent.yaml
COPY /cmd/agent/agent-local-config.yaml /etc/agent/agent.yaml

# Create telescope agent user in container, but do not set it as default
RUN groupadd --gid $UID $USERNAME
Expand Down
85 changes: 85 additions & 0 deletions script/action-ci-clean-up.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
# A simple bash script for cleaning Github Action runner to free up storage.

set -eux

if [ "${GITHUB_ACTIONS}" = "true" ]; then
df -h
echo "::group::/usr/local/*"
du -hsc /usr/local/*
echo "::endgroup::"
# ~1GB
sudo rm -rf \
/usr/local/aws-cli \
/usr/local/aws-sam-cil \
/usr/local/julia* || :
echo "::group::/usr/local/bin/*"
du -hsc /usr/local/bin/*
echo "::endgroup::"
# ~1GB (From 1.2GB to 214MB)
sudo rm -rf \
/usr/local/bin/aliyun \
/usr/local/bin/aws \
/usr/local/bin/aws_completer \
/usr/local/bin/azcopy \
/usr/local/bin/bicep \
/usr/local/bin/cmake-gui \
/usr/local/bin/cpack \
/usr/local/bin/helm \
/usr/local/bin/hub \
/usr/local/bin/kubectl \
/usr/local/bin/minikube \
/usr/local/bin/node \
/usr/local/bin/packer \
/usr/local/bin/pulumi* \
/usr/local/bin/sam \
/usr/local/bin/stack \
/usr/local/bin/terraform || :
# 142M
sudo rm -rf /usr/local/bin/oc || : \
echo "::group::/usr/local/share/*"
du -hsc /usr/local/share/*
echo "::endgroup::"
# 506MB
sudo rm -rf /usr/local/share/chromium || :
# 1.3GB
sudo rm -rf /usr/local/share/powershell || :
echo "::group::/usr/local/lib/*"
du -hsc /usr/local/lib/*
echo "::endgroup::"
# 15GB
sudo rm -rf /usr/local/lib/android || :
# 341MB
sudo rm -rf /usr/local/lib/heroku || :
# 1.2GB
sudo rm -rf /usr/local/lib/node_modules || :
echo "::group::/opt/*"
du -hsc /opt/*
echo "::endgroup::"
# 679MB
sudo rm -rf /opt/az || :
echo "::group::/opt/microsoft/*"
du -hsc /opt/microsoft/*
echo "::endgroup::"
# 197MB
sudo rm -rf /opt/microsoft/powershell || :
echo "::group::/opt/hostedtoolcache/*"
du -hsc /opt/hostedtoolcache/*
echo "::endgroup::"
# 5.3GB
sudo rm -rf /opt/hostedtoolcache/CodeQL || :
# 1.4GB
sudo rm -rf /opt/hostedtoolcache/go || :
# 489MB
sudo rm -rf /opt/hostedtoolcache/PyPy || :
# 376MB
sudo rm -rf /opt/hostedtoolcache/node || :
# Remove Web browser packages
sudo apt purge -y \
firefox \
google-chrome-stable \
microsoft-edge-stable
# remove docker images
docker rmi $(docker image ls -aq) || true
df -h
fi