Skip to content

Commit

Permalink
Merge pull request #13 from text-adi/update_base_image
Browse files Browse the repository at this point in the history
Update base image
  • Loading branch information
text-adi committed Mar 22, 2024
2 parents 8e81baa + f831721 commit d11bb04
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 57 deletions.
83 changes: 44 additions & 39 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,64 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
IMAGE_NAME: aws-kubectl

jobs:
vars:
name: Generation vars
runs-on: ubuntu-latest
outputs:
prefix-test: ${{ steps.basic.outputs.prefix_test }}
steps:
- name: Create basic vars
id: basic
run: |
echo "prefix_test=test" >> $GITHUB_OUTPUT
build_and_push:
needs: [ vars ]
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

- name: Create workdir
run: |
mkdir -p build/kubectl
mkdir -p build/awscli
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Install kubectl
working-directory: build/kubectl
- name: Set test prefix
id: tag
run: |
LATEST_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$LATEST_VERSION/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$LATEST_VERSION/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
echo "Create dir with bin version ./bin" && mkdir ./bin
sudo install -o root -g root -m 0755 ./kubectl ./bin/kubectl
echo "test=${{ secrets.DOCKER_USERNAME }}/${{ vars.APP_NAME }}:${{ needs.vars.outputs.prefix-test }}" >> $GITHUB_OUTPUT
- name: Get version kubectl
working-directory: build/kubectl/bin
id: kubectl
run: echo "version=$(./kubectl version --client -o json | jq '.clientVersion.gitVersion' | tr -d 'v"')" >> $GITHUB_OUTPUT
- name: Build docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
file: Dockerfile
load: true
provenance: false
target: local
tags: |
${{ steps.tag.outputs.test }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Install awscli
working-directory: build/awscli
- name: Get tool version
id: version
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscli.zip" && unzip awscli.zip
sudo ./aws/install --bin-dir ./bin --install-dir ./local --update
ls -la
- name: Get version awscli
working-directory: build/awscli
id: awscli
run: echo "version=$(aws --version | cut -d' ' -f1 | cut -d'/' -f2)" >> $GITHUB_OUTPUT
echo "kubectl=$(docker run --rm ${{ steps.tag.outputs.test }} kubectl version --client -o json | jq '.clientVersion.gitVersion' | tr -d 'v"')" >> $GITHUB_OUTPUT
echo "aws=$(docker run --rm ${{ steps.tag.outputs.test }} aws --version | cut -d' ' -f1 | cut -d'/' -f2)" >> $GITHUB_OUTPUT
- name: Check kubectl and awscli version
run: |
echo "kubectl: '${{ steps.kubectl.outputs.version }}'"
echo "awscli: '${{ steps.awscli.outputs.version }}'"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
echo "kubectl: '${{ steps.version.outputs.kubectl }}'"
echo "aws: '${{ steps.version.outputs.aws }}'"
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
Expand All @@ -75,7 +79,8 @@ jobs:
file: Dockerfile
push: true
provenance: false
target: local
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.awscli.outputs.version }}-${{ steps.kubectl.outputs.version }}
${{ secrets.DOCKER_USERNAME }}/${{ vars.APP_NAME }}:${{ steps.version.outputs.aws }}-${{ steps.version.outputs.kubectl }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
47 changes: 39 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
FROM ubuntu:24.04
FROM alpine:3.18 as builder

LABEL version="1"
LABEL repository="https://github.com/text-adi/aws-kubectl"
LABEL homepage="https://github.com/text-adi"
LABEL maintainer="text-adi <text-adi@github.com>"
ARG GLIBC_VER=2.34-r0

RUN apk --no-cache add \
binutils \
curl \
&& curl -sL https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub \
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk \
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk \
&& apk add --no-cache --force-overwrite \
glibc-${GLIBC_VER}.apk \
glibc-bin-${GLIBC_VER}.apk \
&& curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip \
&& unzip awscliv2.zip \
&& aws/install \
&& LATEST_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt) \
&& curl -LO "https://dl.k8s.io/release/$LATEST_VERSION/bin/linux/amd64/kubectl" \
&& curl -LO "https://dl.k8s.io/release/$LATEST_VERSION/bin/linux/amd64/kubectl.sha256" \
&& echo "$(cat kubectl.sha256) kubectl" | sha256sum -c \
&& install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl \
&& rm -rf \
awscliv2.zip \
aws \
kubectl \
kubectl.sha256 \
/usr/local/aws-cli/v2/*/dist/aws_completer \
/usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \
/usr/local/aws-cli/v2/*/dist/awscli/examples \
&& apk --no-cache del \
binutils \
curl \
&& rm glibc-${GLIBC_VER}.apk \
&& rm glibc-bin-${GLIBC_VER}.apk \
&& rm -rf /var/cache/apk/*


COPY ./build/kubectl /tmp
COPY ./build/awscli/ /tmp
FROM builder as local

RUN install -o root -g root -m 0755 /tmp/kubectl /usr/local/bin/kubectl && /tmp/aws/install && rm -rf /tmp/*
LABEL version="2"
LABEL repository="https://github.com/text-adi/aws-kubectl"
LABEL homepage="https://github.com/text-adi"
LABEL maintainer="text-adi <text-adi@github.com>"
10 changes: 0 additions & 10 deletions script/docker-entrypoint.sh

This file was deleted.

0 comments on commit d11bb04

Please sign in to comment.