Skip to content

Commit 3b6cf5c

Browse files
authored
docker: publish docker images to docker hub (kopia#896)
docker: push dockerhub tags * major.minor - tracks latest major.minor release (except major==0) * latest - tracks official stable releases * testing - tracks official stable releases or pre-releases (beta, rc) * unstable - tracks nightly/unstable builds
1 parent cbcd59f commit 3b6cf5c

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

.github/workflows/make.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ jobs:
4646
# used to publish releases to GitHub by GoReleaser
4747
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
4848

49+
# used to publish docker images
50+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
51+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
52+
4953
# used in Azure tests
5054
KOPIA_AZURE_TEST_CONTAINER: ${{ secrets.KOPIA_AZURE_TEST_CONTAINER }}
5155
KOPIA_AZURE_TEST_STORAGE_ACCOUNT: ${{ secrets.KOPIA_AZURE_TEST_STORAGE_ACCOUNT }}
@@ -109,6 +113,12 @@ jobs:
109113
- name: Install macOS-specific packages
110114
run: "sudo xcode-select -r"
111115
if: ${{ contains(matrix.os, 'macos') }}
116+
- name: Set up QEMU
117+
uses: docker/setup-qemu-action@v1
118+
if: ${{ contains(matrix.os, 'ubuntu') }}
119+
- name: Set up Docker Buildx
120+
uses: docker/setup-buildx-action@v1
121+
if: ${{ contains(matrix.os, 'ubuntu') }}
112122
- name: Check out code into the Go module directory
113123
uses: actions/checkout@v2
114124
with:

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ publish-packages:
325325
ifeq ($(REPO_OWNER)/$(GOOS)/$(GOARCH)/$(IS_PULL_REQUEST),kopia/linux/amd64/false)
326326
$(CURDIR)/tools/apt-publish.sh $(CURDIR)/dist
327327
$(CURDIR)/tools/rpm-publish.sh $(CURDIR)/dist
328+
@echo $(DOCKERHUB_TOKEN) | docker login --username $(DOCKERHUB_USERNAME) --password-stdin
329+
$(CURDIR)/tools/docker-publish.sh
328330
else
329331
@echo Not pushing to Linux repositories on pull request builds.
330332
endif

tools/docker-publish.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -e
3+
DIST_DIR=dist
4+
DOCKER_BUILD_DIR=tools/docker
5+
DOCKERHUB_REPO=kopia/kopia
6+
7+
cp -r "$DIST_DIR/kopia_linux_amd64/" "$DOCKER_BUILD_DIR/bin-amd64/"
8+
cp -r "$DIST_DIR/kopia_linux_arm64/" "$DOCKER_BUILD_DIR/bin-arm64/"
9+
cp -r "$DIST_DIR/kopia_linux_arm_6/" "$DOCKER_BUILD_DIR/bin-arm/"
10+
11+
if [ "$KOPIA_VERSION_NO_PREFIX" == "" ]; then
12+
echo KOPIA_VERSION_NO_PREFIX not set, not publishing.
13+
exit 1
14+
fi
15+
16+
major=$(echo $KOPIA_VERSION_NO_PREFIX | cut -f 1 -d .)
17+
minor=$(echo $KOPIA_VERSION_NO_PREFIX | cut -f 2 -d .)
18+
rev=$(echo $KOPIA_VERSION_NO_PREFIX | cut -f 3 -d .)
19+
20+
# x.y.z
21+
if [[ "$KOPIA_VERSION_NO_PREFIX" =~ [0-9]+\.[0-9]+\.[0-9]+$ ]]; then
22+
extra_tags="latest testing $major $major.$minor"
23+
fi
24+
25+
# x.y.z-prerelease
26+
if [[ "$KOPIA_VERSION_NO_PREFIX" =~ [0-9]+\.[0-9]+\.[0-9]+\-.*$ ]]; then
27+
extra_tags="testing"
28+
fi
29+
30+
# yyyymmdd.0.hhmmss starts with 20
31+
if [[ "$KOPIA_VERSION_NO_PREFIX" =~ 20[0-9]+\.[0-9]+\.[0-9]+ ]]; then
32+
extra_tags="unstable"
33+
fi
34+
35+
versioned_image=$DOCKERHUB_REPO:$KOPIA_VERSION_NO_PREFIX
36+
tags="-t $versioned_image"
37+
for t in $extra_tags; do
38+
if [ "$t" != "0" ]; then
39+
tags="$tags -t $DOCKERHUB_REPO:$t"
40+
fi
41+
done
42+
43+
echo Building $versioned_image with tags [$tags]...
44+
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v6 $tags --push $DOCKER_BUILD_DIR

tools/docker/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM alpine
2+
ARG TARGETARCH
3+
RUN apk add --no-cache --verbose ca-certificates && adduser -D kopia && addgroup kopia kopia
4+
USER kopia:kopia
5+
ENTRYPOINT ["/kopia"]
6+
COPY bin-${TARGETARCH}/kopia /

tools/docker/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DOCKER_BUILD_DIR=.
2+
3+
make:
4+
cp -rv $(CURDIR)/../dist/kopia_linux_amd64/ $(DOCKER_BUILD_DIR)/bin-amd64
5+
cp -rv $(CURDIR)/../dist/kopia_linux_arm64/ $(DOCKER_BUILD_DIR)/bin-arm64
6+
cp -rv $(CURDIR)/../dist/kopia_linux_arm_6/ $(DOCKER_BUILD_DIR)/bin-arm
7+
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v6 -t containers.jkowalski.net/kopia:latest --push $(DOCKER_BUILD_DIR)

tools/docker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a directory for staging pre-built binaries from the `dist/` directory to prevent sending the entire codebase to the docker daemon.

0 commit comments

Comments
 (0)