-
Notifications
You must be signed in to change notification settings - Fork 18
Add docker support (closes #26) #30
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| .git/ | ||
| .github/ | ||
| .idea/ | ||
| data/ | ||
| build/ | ||
| compose.override.yml |
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: CI |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| version: 2 | ||
| updates: | ||
|
|
||
| # Maintain dependencies for GitHub Actions | ||
| - package-ecosystem: "github-actions" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" | ||
|
|
||
| # Maintain Docker image dependencies | ||
| - package-ecosystem: "docker" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "monthly" |
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: CI Automatically build: Every seventh day (Sunday) of the week at 05:00 AM |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| name: Build docker image | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| schedule: | ||
| - cron: "0 5 * * */7" | ||
| push: | ||
| branches: master | ||
| paths: | ||
| - .github/workflows/image.yml | ||
| - .dockerignore | ||
| - Dockerfile | ||
| - hack/docker-bake.hcl | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| steps: | ||
| - name: checkout code | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@v3 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Login to GitHub Container Registry | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Export image repository name | ||
| run: | | ||
| echo "IMAGE_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | ||
| env: | ||
| GITHUB_REPOSITORY: ${{ github.repository }} | ||
|
|
||
| - name: Build and push images | ||
| uses: docker/bake-action@v6.10.0 | ||
| with: | ||
| files: hack/docker-bake.hcl | ||
| push: true | ||
| env: | ||
| GIT_SHA: ${{ github.sha }} | ||
| GITHUB_REPOSITORY: ${{ github.repository }} | ||
| IMAGE_NAME: ghcr.io/${{ env.IMAGE_REPOSITORY }} | ||
| REGISTRY_CACHE: ghcr.io/${{ env.IMAGE_REPOSITORY }}-cache |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| ARG BBKCLI_VERSION=1.0 | ||
|
|
||
| FROM alpine:3.23 AS bbkcli | ||
|
|
||
| # See: http://www.bredbandskollen.se/bredbandskollen-cli/ | ||
| ARG BBKCLI_VERSION | ||
| ARG TARGETPLATFORM | ||
| RUN case ${TARGETPLATFORM} in \ | ||
| "linux/amd64") BBKCLI_ARCH=amd64 ;; \ | ||
| "linux/arm64") BBKCLI_ARCH=aarch64 ;; \ | ||
| "linux/arm/v7") BBKCLI_ARCH=armhf ;; \ | ||
| "linux/386") BBKCLI_ARCH=i386 ;; \ | ||
| esac \ | ||
| && echo "Fetch: https://frontend.bredbandskollen.se/download/bbk_cli_linux_${BBKCLI_ARCH:-amd64}-${BBKCLI_VERSION}" \ | ||
| && wget -q https://frontend.bredbandskollen.se/download/bbk_cli_linux_${BBKCLI_ARCH:-amd64}-${BBKCLI_VERSION} -O /bbk_cli | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uses prebuilt library. I can change it to build from source, if desired. |
||
|
|
||
| COPY ["./LICENSE", "/bbk_cli_license"] | ||
|
|
||
|
|
||
|
|
||
| # Main image | ||
| FROM alpine:3.23 | ||
|
|
||
| RUN apk add --update --no-cache gcompat libstdc++ tzdata \ | ||
| && ln -sf /usr/local/bin/bbk_cli /usr/local/bin/bbk | ||
|
|
||
| COPY --from=bbkcli --chmod=0775 ["/bbk_cli", "/usr/local/bin/"] | ||
| COPY --from=bbkcli --chmod=0755 ["/bbk_cli_license", "/usr/local/src/bbk/LICENSE.txt"] | ||
|
|
||
| ARG BBKCLI_VERSION | ||
| ARG TARGETPLATFORM | ||
| ENV BBKCLI_VERSION=${BBKCLI_VERSION} | ||
| ENV PLATFORM_ARCH=${TARGETPLATFORM} | ||
| ENV TZ=Europe/Stockholm | ||
|
|
||
| LABEL org.opencontainers.image.title="Bredbandskollen CLI" \ | ||
| org.opencontainers.image.description="Bredbandskollen CLI, a bandwidth measurement tool" \ | ||
| org.opencontainers.image.authors="The Swedish Internet Foundation <support@bredbandskollen.se>" \ | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what to put here. Please validate. |
||
| org.opencontainers.image.vendor="The Swedish Internet Foundation" \ | ||
| org.opencontainers.image.url="https://www.bredbandskollen.se/om/mer-om-bbk/bredbandskollen-cli/" \ | ||
| org.opencontainers.image.licenses="MIT" | ||
|
|
||
| ENTRYPOINT [ "/usr/local/bin/bbk_cli" ] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: CI |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| group "default" { | ||
| targets = ["regular"] | ||
| } | ||
|
|
||
| variable "IMAGE_NAME" { | ||
| default = "ghcr.io/dotse/bbk" | ||
| } | ||
|
|
||
| variable "REGISTRY_CACHE" { | ||
| default = "ghcr.io/dotse/bbk-cache" | ||
| } | ||
|
|
||
| variable "GIT_SHA" { | ||
| default = "local-dev" | ||
| } | ||
|
|
||
| variable "GITHUB_REPOSITORY" { | ||
| default = "dotse/bbk" | ||
| } | ||
|
|
||
| variable "BBKCLI_VERSIONS" { | ||
| default = { | ||
| "1.0.0" = { | ||
| version = "1.0" | ||
| extra_tags = ["1.0.0"] | ||
| } | ||
| "1.2.2" = { | ||
| version = "1.2.2" | ||
| extra_tags = ["1", "1.2", "latest"] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| target "build-dockerfile" { | ||
| dockerfile = "Dockerfile" | ||
| } | ||
|
|
||
| target "build-platforms" { | ||
| platforms = ["linux/amd64", "linux/arm64"] | ||
| } | ||
|
|
||
| target "build-common" { | ||
| pull = true | ||
| } | ||
|
|
||
| # Get the arguments for the build | ||
| function "get-args" { | ||
| params = [bbkcli_version] | ||
| result = { | ||
| BBKCLI_VERSION = bbkcli_version | ||
| } | ||
| } | ||
|
|
||
| # Get the cache-from configuration | ||
| function "get-cache-from" { | ||
| params = [version] | ||
| result = [ | ||
| "type=registry,ref=${REGISTRY_CACHE}:${sha1("${version}-${BAKE_LOCAL_PLATFORM}")}", | ||
| "type=registry,ref=${REGISTRY_CACHE}:${sha1("master-${BAKE_LOCAL_PLATFORM}")}" | ||
| ] | ||
| } | ||
|
|
||
| # Get the cache-to configuration | ||
| function "get-cache-to" { | ||
| params = [version] | ||
| result = [ | ||
| "type=registry,mode=max,ref=${REGISTRY_CACHE}:${sha1("${version}-${BAKE_LOCAL_PLATFORM}")}", | ||
| "type=registry,mode=max,ref=${REGISTRY_CACHE}:${sha1("master-${BAKE_LOCAL_PLATFORM}")}" | ||
| ] | ||
| } | ||
|
|
||
| # Get list of image tags and registries | ||
| function "get-tags" { | ||
| params = [version, extra_versions] | ||
| result = concat( | ||
| [ | ||
| "${IMAGE_NAME}:${version}" | ||
| ], | ||
| flatten([ | ||
| for extra_version in extra_versions : [ | ||
| "${IMAGE_NAME}:${extra_version}" | ||
| ] | ||
| ]) | ||
| ) | ||
| } | ||
|
|
||
| target "regular" { | ||
| inherits = ["build-dockerfile", "build-platforms", "build-common"] | ||
| matrix = { | ||
| version = keys(BBKCLI_VERSIONS) | ||
| } | ||
|
|
||
| name = replace(version, ".", "_") | ||
| args = get-args(BBKCLI_VERSIONS[version].version) | ||
| tags = get-tags(version, BBKCLI_VERSIONS[version].extra_tags) | ||
| cache-from = get-cache-from(version) | ||
| cache-to = get-cache-to(version) | ||
| labels = { | ||
| "org.opencontainers.image.created" = "${timestamp()}" | ||
| "org.opencontainers.image.version" = BBKCLI_VERSIONS[version].version | ||
| "org.opencontainers.image.revision" = GIT_SHA | ||
| "org.opencontainers.image.source" = "https://github.com/${GITHUB_REPOSITORY}" | ||
| "org.opencontainers.image.documentation" = "https://github.com/${GITHUB_REPOSITORY}/blob/master/README.md" | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required, but recommended optimisation as it ensures that the context sent to Docker is minimal. Depending on the repository, this might have a huge impact.