From cd3c88af8e0da30cef4d9ce5ca40ee35620d8406 Mon Sep 17 00:00:00 2001 From: Navratan Lal Gupta Date: Sun, 30 Apr 2023 23:54:02 +0530 Subject: [PATCH] Docker image for k8senv --- .github/workflows/release.yml | 30 ++++++++++++++++++++++++++++++ Dockerfile | 25 +++++++++++++++++++++++++ container_image_build.sh | 14 ++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 Dockerfile create mode 100755 container_image_build.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7b2c45b..ff59089 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -158,3 +158,33 @@ jobs: k8senv-linux-arm64 CHECKSUM generate_release_notes: true + + docker-push: + name: docker-push + needs: [test-linux] + runs-on: ubuntu-latest + steps: + - name: 🛎️ Checkout + uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Genarate Tag + run: | + #!/usr/bin/env bash + tag=$(echo "${{ github.ref }}" | rev | cut -d "/" -f 1 | rev) + echo "TAGID=$tag" >> "$GITHUB_OUTPUT" + id: generate-tag + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/k8senv:latest,${{ secrets.DOCKERHUB_USERNAME }}/k8senv:${{ steps.generate-tag.outputs.TAGID }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dfa497e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM golang:1.20.3-alpine3.17 as build +ARG OS +ARG ARCH +WORKDIR /build +COPY . . +RUN apk add git +RUN go mod download && \ + CGO_ENABLED=0 go build -o k8senv + +FROM alpine:3.17 +ARG VERSION +ARG user=k8senv +ARG group=k8senv +ARG uid=1000 +ARG gid=1000 +USER root +WORKDIR /app +COPY --from=build /build/k8senv /app/.k8senv/bin/k8senv +RUN apk update && apk --no-cache add bash vim && addgroup -g ${gid} ${group} && adduser -h /app -u ${uid} -G ${group} -s /bin/bash -D ${user} +RUN chown -R k8senv:k8senv /app/.k8senv && chmod -R u+rx /app/.k8senv +USER k8senv +ENV PATH="/app/.k8senv/bin:$PATH" +VOLUME /app/.k8senv/ +ENTRYPOINT [ "k8senv"] +CMD ["help"] \ No newline at end of file diff --git a/container_image_build.sh b/container_image_build.sh new file mode 100755 index 0000000..d35d5af --- /dev/null +++ b/container_image_build.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# Docker image + +version=$(go run main.go version | cut -d " " -f 2 | jq .K8senv | tr -d "\"") +docker buildx create --name dockerxbuilder --use --bootstrap + +if [ "$1" == "push" ]; then + docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v7 --tag linuxshots/k8senv:$version . + docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v7 --tag linuxshots/k8senv . +else + docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --tag linuxshots/k8senv:$version . + docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --tag linuxshots/k8senv . +fi