Skip to content

Commit

Permalink
Fix push script
Browse files Browse the repository at this point in the history
  • Loading branch information
robbertkl committed Sep 17, 2019
1 parent 6a96709 commit 7ce01cb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.git/
build/
dist/
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.DS_Store
build/
dist/
1 change: 1 addition & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"hooks": {
"before:bump": "sed -E -i '' 's/^const buildVersion = .*$/const buildVersion = \"${version}\"/' cmd/docker-ipv6nat/main.go",
"after:bump": "./push.sh ${version}",
"after:release": "rm -Rf dist/"
},
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
FROM --platform=$BUILDPLATFORM golang:1.13.0-alpine3.10 AS build
ARG TARGETPLATFORM
ARG VERSION
WORKDIR /go/src/github.com/robbertkl/docker-ipv6nat
COPY . .
RUN [ "$TARGETPLATFORM" = "linux/amd64" ] && echo GOOS=linux GOARCH=amd64 > .env || true
RUN [ "$TARGETPLATFORM" = "linux/arm64" ] && echo GOOS=linux GOARCH=arm64 > .env || true
RUN [ "$TARGETPLATFORM" = "linux/arm/v6" ] && echo GOOS=linux GOARCH=arm GOARM=6 > .env || true
RUN [ "$TARGETPLATFORM" = "linux/arm/v7" ] && echo GOOS=linux GOARCH=arm GOARM=7 > .env || true
ENV CGO_ENABLED=0
RUN env $(cat .env | xargs) go build -o /docker-ipv6nat -ldflags "-X main.buildVersion=$VERSION" ./cmd/docker-ipv6nat
RUN env $(cat .env | xargs) go build -o /docker-ipv6nat.$(echo "$TARGETPLATFORM" | sed -E 's/(^linux|\/)//g') ./cmd/docker-ipv6nat

FROM alpine:3.10 AS release
RUN apk add --no-cache ip6tables
COPY --from=build /docker-ipv6nat /
COPY --from=build /docker-ipv6nat.* /docker-ipv6nat
COPY docker-ipv6nat-compat /
ENTRYPOINT ["/docker-ipv6nat-compat"]
CMD ["--retry"]
4 changes: 2 additions & 2 deletions cmd/docker-ipv6nat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/robbertkl/docker-ipv6nat"
)

var (
buildVersion string
const buildVersion = "0.3.8"

var (
cleanup bool
retry bool
userlandProxy bool
Expand Down
36 changes: 18 additions & 18 deletions push.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
#!/bin/sh

cd `dirname "${0}"`

VERSION="${1}"
BUILDER=ipv6nat-builder
PLATFORMS="linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7"
BUILD_DIR=build
DIST_DIR=dist
VERSION="${1}"

if [ -z "${VERSION}" ]
then
echo "Usage: ${0} X.X.X"
exit 1
fi

DOCKER_TLS_VERIFY=
DOCKER_HOST=
DOCKER_CERT_PATH=
DOCKER_MACHINE_NAME=
DOCKER_VERSION="system"

cd `dirname "${0}"`

set -e
set -x

docker buildx rm "${BUILDER}" || true
docker buildx create --name "${BUILDER}" --use
docker buildx build \
--platform "${PLATFORMS}" \
--platform "linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7" \
--pull \
--build-arg "VERSION=${VERSION}" \
--output "type=local,dest=${BUILD_DIR}" \
--push
--push \
--tag "robbertkl/ipv6nat:${VERSION}" \
--tag "robbertkl/ipv6nat:latest" \
.

BUILDER_CONTAINER="buildx_buildkit_${BUILDER}0"
docker exec "${BUILDER_CONTAINER}" sh -c \
'mkdir /dist; mv /var/lib/buildkit/runc-overlayfs/snapshots/snapshots/*/fs/docker-ipv6nat.* /dist'
rm -Rf "${DIST_DIR}/"
docker cp "${BUILDER_CONTAINER}:/dist" "${DIST_DIR}"

docker buildx use default
docker buildx rm "${BUILDER}"

mkdir -p "${DIST_DIR}"
for PLATFORM in `echo "${PLATFORMS}" | sed 's/,/ /g'`
do
PLATFORM_BUILD_DIR="${BUILD_DIR}/`echo "${PLATFORM}" | sed -E 's/\//_/g'`"
PLATFORM_TAG="`echo "${PLATFORM}" | sed -E 's/(^linux|\/)//g'`"
mv "${PLATFORM_BUILD_DIR}/docker-ipv6nat" "${DIST_DIR}/docker-ipv6nat.${PLATFORM_TAG}"
done
rm -Rf "${BUILD_DIR}/"

0 comments on commit 7ce01cb

Please sign in to comment.