Skip to content

Commit

Permalink
Merge pull request #23 from navilg/21-k8senv-build-a-docker-image-for…
Browse files Browse the repository at this point in the history
…-k8senv-to-use-make-it-usable-in-any-cicd-pipeline

Docker image for k8senv
  • Loading branch information
navilg authored Apr 30, 2023
2 parents 557352e + cd3c88a commit 32e7596
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 14 additions & 0 deletions container_image_build.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 32e7596

Please sign in to comment.