Skip to content

Commit a9dfd8b

Browse files
🔧 Update all scripts to debug from beg
1 parent 95c1cd2 commit a9dfd8b

File tree

5 files changed

+169
-136
lines changed

5 files changed

+169
-136
lines changed

.github/workflows/docker.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build & Push Docker Image to Docker Hub
2+
3+
on:
4+
push:
5+
branches:
6+
- devlop # Trigger on pushes to the main branch
7+
workflow_dispatch: # Allows manual triggering of the workflow
8+
9+
jobs:
10+
build_and_push:
11+
runs-on: ubuntu-latest # Use the latest Ubuntu runner
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4 # Action to check out your repository code
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3 # Action to set up Docker Buildx for improved build capabilities
19+
20+
- name: Log in to Docker Hub
21+
uses: docker/login-action@v3 # Action to log into Docker Hub
22+
with:
23+
username: ${{ secrets.DOCKER_USERNAME }} # Use GitHub secret for Docker Hub username
24+
password: ${{ secrets.DOCKER_PASSWORD }} # Use GitHub secret for Docker Hub PAT
25+
26+
- name: Build and push Docker image
27+
uses: docker/build-push-action@v5 # Action to build and push Docker images
28+
with:
29+
context: . # Build context is the current directory (where Dockerfile is located)
30+
push: true # Enable pushing the image to Docker Hub
31+
tags: |
32+
${{ secrets.DOCKER_USERNAME }}/eks-helm-client-test:latest # Tag with 'latest'
33+
${{ secrets.DOCKER_USERNAME }}/eks-helm-client-test:${{ github.sha }}
34+
# build-args: |
35+
# K8_VERSION=1.30.2
36+
# HELM_VERSION=3.14.4
37+
# IAM_AUTHENTICATOR_VERSION=0.6.20

Dockerfile

Lines changed: 47 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,64 @@
1-
FROM alpine:3.18
1+
# Use the specified Alpine base image
2+
FROM projectoss/alpine:3.14
23

3-
# Metadata
4-
LABEL maintainer="dinushchathurya21@gmail.com"
5-
LABEL version="2.0.0"
6-
LABEL description="EKS Helm Client with private infrastructure support"
7-
LABEL org.opencontainers.image.source="https://github.com/open-source-srilanka/eks-helm-client-github-action"
8-
LABEL org.opencontainers.image.description="Deploy Helm charts to EKS clusters with support for private clusters and registries"
9-
LABEL org.opencontainers.image.licenses="MIT"
10-
11-
# Install base packages
12-
RUN apk add --no-cache \
13-
ca-certificates \
14-
bash \
15-
git \
16-
gnupg \
17-
jq \
18-
curl \
19-
gettext \
20-
openssl \
21-
py3-pip \
22-
python3 \
23-
netcat-openbsd \
24-
&& pip3 install --upgrade awscli \
25-
&& rm -rf /var/cache/apk/*
26-
27-
# Set environment variables
4+
# Set the KUBECONFIG environment variable to define where kubectl will look for its config file
285
ENV KUBECONFIG="/opt/kubernetes/config"
29-
ENV HELM_HOME="/opt/helm"
30-
ENV XDG_CONFIG_HOME="/opt/helm"
31-
ENV HELM_CACHE_HOME="/opt/helm/cache"
32-
ENV HELM_CONFIG_HOME="/opt/helm"
33-
ENV HELM_DATA_HOME="/opt/helm"
34-
ENV PATH="/usr/local/bin:$PATH"
356

36-
# Install kubectl (version will be overridden by input parameter)
37-
ARG KUBECTL_VERSION="1.28.4"
38-
RUN curl -s -L "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl" -o /usr/local/bin/kubectl \
7+
# Install necessary packages:
8+
# ca-certificates: For validating SSL/TLS connections
9+
# bash: Shell environment
10+
# git: For cloning Git repositories, potentially private Helm charts
11+
# gnupg: For verifying signed Helm charts or other secured assets (already present, ensuring it's there)
12+
# jq: A lightweight and flexible command-line JSON processor
13+
# py-pip: Python package installer, used for awscli
14+
# curl: Tool for transferring data with URL syntax (already present, ensuring it's there)
15+
# gettext: GNU gettext for internationalization (already present)
16+
RUN apk add --no-cache ca-certificates bash git gnupg jq py-pip \
17+
&& apk add --update -t deps curl gettext \
18+
&& pip install awscli
19+
20+
# Define argument for Kubernetes client (kubectl) version
21+
# Updated to a more recent stable version for better compatibility with newer EKS clusters
22+
ARG K8_VERSION="1.30.2"
23+
# Download and install kubectl
24+
RUN curl -s -L https://dl.k8s.io/release/v${K8_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl \
3925
&& chmod +x /usr/local/bin/kubectl
4026

41-
# Install Helm (version will be overridden by input parameter)
42-
ARG HELM_VERSION="3.13.3"
43-
RUN curl -s -L "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar -xzO linux-amd64/helm > /usr/local/bin/helm \
27+
# Define argument for Helm version
28+
# Updated to the latest stable version for Helm 3
29+
ARG HELM_VERSION="3.14.4"
30+
# Download and install Helm
31+
RUN curl -s -L https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz | tar -xzO linux-amd64/helm > /usr/local/bin/helm \
4432
&& chmod +x /usr/local/bin/helm
4533

46-
# Install AWS IAM Authenticator
47-
ARG IAM_AUTHENTICATOR_VERSION="0.6.14"
48-
RUN curl -o aws-iam-authenticator "https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v${IAM_AUTHENTICATOR_VERSION}/aws-iam-authenticator_${IAM_AUTHENTICATOR_VERSION}_linux_amd64" \
34+
# Define argument for AWS IAM Authenticator version
35+
# Updated to a more recent stable version
36+
ARG IAM_AUTHENTICATOR_VERSION="0.6.20"
37+
# Download, make executable, and move aws-iam-authenticator
38+
RUN curl -o aws-iam-authenticator https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v${IAM_AUTHENTICATOR_VERSION}/aws-iam-authenticator_${IAM_AUTHENTICATOR_VERSION}_linux_amd64 \
4939
&& chmod +x ./aws-iam-authenticator \
5040
&& mv ./aws-iam-authenticator /usr/local/bin
5141

52-
# Install eksctl for additional EKS operations
53-
RUN curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp \
54-
&& mv /tmp/eksctl /usr/local/bin
42+
# Clean up APK cache to reduce image size
43+
RUN rm -rf /var/cache/apk/*
5544

56-
# Create necessary directories with proper permissions
57-
RUN mkdir -p /opt/kubernetes /opt/helm /opt/scripts && \
58-
chmod a+rwx /opt/kubernetes /opt/helm /opt/scripts
45+
# Create directories for Kubernetes config and Helm, and set appropriate permissions
46+
# These directories are used for storing configurations and cache
47+
RUN mkdir -p /opt/kubernetes && chmod a+rwx /opt/kubernetes && mkdir -p /opt/helm && chmod a+rwx /opt/helm
5948

60-
# Create non-root user for better security
61-
RUN addgroup -g 1000 runner && \
62-
adduser -D -u 1000 -G runner runner && \
63-
chown -R runner:runner /opt/kubernetes /opt/helm /opt/scripts
64-
65-
# Copy configuration files and scripts
66-
COPY templates/config.template /config.template
67-
COPY templates/private-config.template /private-config.template
68-
COPY scripts/entrypoint.sh /entrypoint.sh
69-
COPY scripts/health-check.sh /health-check.sh
70-
COPY scripts/setup-tools.sh /setup-tools.sh
71-
COPY scripts/cleanup.sh /cleanup.sh
72-
73-
# Set proper permissions for scripts
74-
RUN chmod +x /entrypoint.sh /health-check.sh /setup-tools.sh /cleanup.sh && \
75-
chown runner:runner /entrypoint.sh /health-check.sh /setup-tools.sh /cleanup.sh
49+
# Set Helm environment variables for cache and config home
50+
ENV HELM_HOME="/opt/helm"
51+
ENV XDG_CONFIG_HOME="/opt/helm"
52+
ENV HELM_CACHE_HOME="/opt/helm/cache"
7653

7754
# Set working directory
78-
WORKDIR /opt/scripts
55+
WORKDIR /
7956

80-
# Add health check
81-
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
82-
CMD /health-check.sh
57+
# Copy the entire context into the container. This should include entrypoint.sh and config.template
58+
ADD . .
8359

84-
# Security: Use non-root user for execution
85-
USER runner
60+
# Make the entrypoint script executable
61+
RUN chmod +x entrypoint.sh
8662

87-
# Set the entrypoint
88-
ENTRYPOINT ["/entrypoint.sh"]
63+
# Set the entrypoint for the Docker container
64+
ENTRYPOINT [ "/entrypoint.sh" ]

action.yml

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,13 @@
1+
# action.yml
12
name: 'EKS Helm Client'
2-
description: 'Helm client to install and upgrade Helm chart on EKS cluster with support for private clusters and repositories'
3-
author: 'Open Source Sri Lanka'
3+
description: 'Helm client to install and upgrade Helm chart on EKS cluster'
44
branding:
55
icon: 'upload-cloud'
66
color: 'blue'
7-
87
runs:
98
using: 'docker'
109
image: 'Dockerfile'
11-
1210
inputs:
1311
args:
14-
description: 'Commands to install and upgrade Helm chart'
15-
required: true
16-
17-
cluster-name:
18-
description: 'EKS cluster name (falls back to CLUSTER_NAME env var if not provided)'
19-
required: true
20-
21-
region:
22-
description: 'AWS region where the EKS cluster is located (falls back to REGION_CODE env var if not provided)'
23-
required: true
24-
25-
private-cluster:
26-
description: 'Set to true if EKS cluster is private (default: false)'
27-
required: false
28-
default: 'false'
29-
30-
helm-registry-url:
31-
description: 'Private Helm registry URL'
32-
required: false
33-
34-
helm-registry-username:
35-
description: 'Username for private Helm registry'
36-
required: false
37-
38-
helm-registry-password:
39-
description: 'Password for private Helm registry'
40-
required: false
41-
42-
helm-registry-insecure:
43-
description: 'Allow insecure connection to Helm registry (default: false)'
44-
required: false
45-
default: 'false'
46-
47-
kubectl-version:
48-
description: 'Kubectl version to use (default: 1.28.4)'
49-
required: false
50-
default: '1.28.4'
51-
52-
helm-version:
53-
description: 'Helm version to use (default: 3.13.3)'
54-
required: false
55-
default: '3.13.3'
56-
57-
timeout:
58-
description: 'Timeout for kubectl and helm operations in seconds (default: 300)'
59-
required: false
60-
default: '300'
61-
62-
debug:
63-
description: 'Enable debug logging (default: false)'
64-
required: false
65-
default: 'false'
66-
67-
kubeconfig-path:
68-
description: 'Custom path for kubeconfig file'
69-
required: false
70-
71-
dry-run:
72-
description: 'Perform a dry run without making actual changes (default: false)'
73-
required: false
74-
default: 'false'
12+
description: Commands need to install and upgrade Helm chart
13+
required: true

config.template

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# config.template
2+
apiVersion: v1
3+
clusters:
4+
- cluster:
5+
certificate-authority-data: ${CA_CERT}
6+
server: ${ENDPOINT_URL}
7+
name: kubernetes
8+
contexts:
9+
- context:
10+
cluster: kubernetes
11+
user: aws
12+
name: aws
13+
current-context: aws
14+
kind: Config
15+
preferences: {}
16+
users:
17+
- name: aws
18+
user:
19+
exec:
20+
apiVersion: client.authentication.k8s.io/v1beta1
21+
command: aws
22+
args:
23+
- "eks"
24+
- "get-token"
25+
- "--cluster-name"
26+
- "${CLUSTER_NAME}"
27+
- "--region"
28+
- "${REGION_CODE}"
29+
# Provide a path to the aws-iam-authenticator binary if it's not in the PATH
30+
# env:
31+
# - name: PATH
32+
# value: "/usr/local/bin:${PATH}"
33+
# install aws-iam-authenticator in the Dockerfile if not already.

entrypoint.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# This script is the entrypoint for the GitHub Action Docker container.
5+
# It sets up the Kubeconfig for EKS access and then executes the commands passed to the action.
6+
7+
echo "--- Configuring AWS EKS Kubeconfig ---"
8+
9+
# Export CA_CERT: Fetches the certificate authority data for the EKS cluster.
10+
# This is crucial for kubectl to trust the EKS API server.
11+
# REGION_CODE and CLUSTER_NAME are expected to be set as environment variables
12+
# by the GitHub Actions workflow (e.g., via the `env` block in `action.yml`).
13+
export CA_CERT=$(aws eks describe-cluster --region "$REGION_CODE" --name "$CLUSTER_NAME" --query "cluster.certificateAuthority.data" --output text)
14+
if [ -z "$CA_CERT" ]; then
15+
echo "Error: Could not retrieve EKS cluster certificate authority data. Check REGION_CODE and CLUSTER_NAME."
16+
exit 1
17+
fi
18+
19+
# Export ENDPOINT_URL: Fetches the endpoint URL for the EKS cluster.
20+
export ENDPOINT_URL=$(aws eks describe-cluster --region "$REGION_CODE" --name "$CLUSTER_NAME" --query "cluster.endpoint" --output text)
21+
if [ -z "$ENDPOINT_URL" ]; then
22+
echo "Error: Could not retrieve EKS cluster endpoint URL. Check REGION_CODE and CLUSTER_NAME."
23+
exit 1
24+
fi
25+
26+
echo "EKS Cluster Endpoint: $ENDPOINT_URL"
27+
28+
# Generate Kubernetes configuration file (/opt/kubernetes/config)
29+
# This file tells kubectl how to connect to the EKS cluster.
30+
# It uses /config.template (expected to be present in the Docker image)
31+
# and substitutes environment variables (CA_CERT, ENDPOINT_URL).
32+
# The KUBECONFIG environment variable is already set in the Dockerfile
33+
# to point to this location.
34+
cat /config.template | envsubst > /opt/kubernetes/config
35+
36+
# Verify the generated Kubeconfig (optional, for debugging)
37+
echo "Generated Kubeconfig:"
38+
cat /opt/kubernetes/config
39+
echo "----------------------"
40+
41+
# Ensure KUBECONFIG environment variable is correctly set for subsequent commands
42+
export KUBECONFIG=/opt/kubernetes/config
43+
44+
echo "--- Executing Helm Commands ---"
45+
# Execute the commands passed as arguments to the action (e.g., Helm commands)
46+
# The "$@" expands to all positional parameters passed to the script,
47+
# which corresponds to the `args` input in your `action.yml`.
48+
exec "$@"

0 commit comments

Comments
 (0)