From 51e27881421988dbf4689f693f8d288b5a6a4f2b Mon Sep 17 00:00:00 2001 From: Jimmy <14042259+jabez007@users.noreply.github.com> Date: Tue, 27 Aug 2024 09:20:31 -0500 Subject: [PATCH] fix "string" comparison in action --- .github/shared/docker/action.yml | 2 +- Dockerfile | 136 +++++++++++++++---------------- README.md | 132 +++++++++++++++--------------- entrypoint.sh | 20 ++--- 4 files changed, 145 insertions(+), 145 deletions(-) diff --git a/.github/shared/docker/action.yml b/.github/shared/docker/action.yml index 4f3364d..6dd37f3 100644 --- a/.github/shared/docker/action.yml +++ b/.github/shared/docker/action.yml @@ -83,7 +83,7 @@ runs: outputs: type=docker,dest=/tmp/${{ github.event.repository.name }}.tar - name: Upload image artifacts - if: ${{ inputs.push != true }} + if: ${{ inputs.push != 'true' }} uses: actions/upload-artifact@v2 with: name: ${{ steps.git_commit.outputs.short_hash }} diff --git a/Dockerfile b/Dockerfile index aaeff2d..b807bca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,69 +1,69 @@ -FROM --platform=$BUILDPLATFORM debian:stable-slim - -ARG AWS_REGION -ARG EKS_CLUSTER - -# Set target architecture variable -ARG TARGETARCH - -# Enable the arm64 architecture -RUN if [ "$TARGETARCH" = "arm64" ]; then \ - dpkg --add-architecture arm64; \ - fi - - -# Install dependencies -RUN apt-get update && apt-get install -y \ - unzip \ - bash \ - curl \ - jq \ - yq - -# Install dependency for AWS CLI on arm64 -RUN if [ "$TARGETARCH" = "arm64" ]; then \ - apt-get install -y \ - libc6:arm64 \ - zlib1g:arm64; \ - fi - -# Clean up apt-get afterwards -RUN rm -rf /var/lib/apt/lists/* - -# Install kubectl -RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${TARGETARCH}/kubectl" \ - && install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl - -# Verify kubectl install -RUN kubectl version --client - -# Install aws cli -RUN if [ "$TARGETARCH" = "arm64" ]; then \ - curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"; \ - else \ - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"; \ - fi \ - && unzip awscliv2.zip \ - && ./aws/install \ - && rm -rf awscliv2.zip aws - -# Verify aws cli install -RUN aws --version - -# Add aliases to .bashrc -RUN echo "alias update-kubeconfig='aws eks update-kubeconfig --region ${AWS_REGION} --name ${EKS_CLUSTER}'" >> /root/.bashrc - -# Copy the entrypoint script into the container -COPY entrypoint.sh /usr/local/bin/entrypoint.sh - -# Make the entrypoint script executable -RUN chmod +x /usr/local/bin/entrypoint.sh - -# Set the entrypoint to the script -ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] - -# Set the working directory -WORKDIR /home/root - -# Set bash as the default shell +FROM --platform=$BUILDPLATFORM debian:stable-slim + +ARG AWS_REGION +ARG EKS_CLUSTER + +# Set target architecture variable +ARG TARGETARCH + +# Enable the arm64 architecture +RUN if [ "$TARGETARCH" = "arm64" ]; then \ + dpkg --add-architecture arm64; \ + fi + + +# Install dependencies +RUN apt-get update && apt-get install -y \ + unzip \ + bash \ + curl \ + jq \ + yq + +# Install dependency for AWS CLI on arm64 +RUN if [ "$TARGETARCH" = "arm64" ]; then \ + apt-get install -y \ + libc6:arm64 \ + zlib1g:arm64; \ + fi + +# Clean up apt-get afterwards +RUN rm -rf /var/lib/apt/lists/* + +# Install kubectl +RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${TARGETARCH}/kubectl" \ + && install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl + +# Verify kubectl install +RUN kubectl version --client + +# Install aws cli +RUN if [ "$TARGETARCH" = "arm64" ]; then \ + curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"; \ + else \ + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"; \ + fi \ + && unzip awscliv2.zip \ + && ./aws/install \ + && rm -rf awscliv2.zip aws + +# Verify aws cli install +RUN aws --version + +# Add aliases to .bashrc +RUN echo "alias update-kubeconfig='aws eks update-kubeconfig --region ${AWS_REGION} --name ${EKS_CLUSTER}'" >> /root/.bashrc + +# Copy the entrypoint script into the container +COPY entrypoint.sh /usr/local/bin/entrypoint.sh + +# Make the entrypoint script executable +RUN chmod +x /usr/local/bin/entrypoint.sh + +# Set the entrypoint to the script +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + +# Set the working directory +WORKDIR /home/root + +# Set bash as the default shell CMD ["/bin/bash"] \ No newline at end of file diff --git a/README.md b/README.md index 6aed79c..ffcf465 100644 --- a/README.md +++ b/README.md @@ -1,66 +1,66 @@ -# aws-kubectl - -This repository provides a Dockerfile to build an image with the AWS CLI and `kubectl` installed. -The image includes a startup script that ensures AWS Single Sign-On (SSO) is configured when the container starts. -Additionally, the image configures an alias in the `.bashrc` to update the kubeconfig with the specified AWS region and EKS cluster name. - -## Features - -- AWS CLI pre-installed -- `kubectl` pre-installed -- Automatic SSO configuration at startup -- Alias for updating kubeconfig with AWS region and EKS cluster - -## Build Arguments - -The Docker image build requires the following arguments: - -- `AWS_REGION`: The AWS region where your EKS cluster is located. -- `EKS_CLUSTER`: The name of your EKS cluster. - -### Build the Docker Image - -To build the Docker image with the required arguments, run: - -```bash -docker build --build-arg AWS_REGION= --build-arg EKS_CLUSTER= -t aws-kubectl . -``` - -### Running the Container - -To run the container, ensure your local `.aws` directory is mounted to the container's `/root/.aws` directory. This allows the container to access your AWS configurations and credentials, including SSO profiles. - -#### Example for Linux/macOS, Windows with WSL, or Git Bash - -```bash -docker run -it --rm -v ~/.aws:/root/.aws aws-kubectl -``` - -#### Example for Windows with PowerShell - -```powershell -docker run -it --rm -v ${env:USERPROFILE}\.aws:/root/.aws aws-kubectl -``` - -### Using the Kubeconfig Alias - -Once the container is running, you can use the configured alias to update your kubeconfig: - -```bash -update-kubeconfig -``` - -This command automatically updates the kubeconfig with the AWS region and EKS cluster name specified during the build. - -### Notes - -- The container must have access to your AWS credentials, so mounting your `.aws` directory is necessary. -- The startup script will check if SSO is configured and prompt you if additional steps are required. - -## Contributing - -Feel free to open issues or submit pull requests if you find any bugs or have suggestions for improvements. - -## License - -This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. +# aws-kubectl + +This repository provides a Dockerfile to build an image with the AWS CLI and `kubectl` installed. +The image includes a startup script that ensures AWS Single Sign-On (SSO) is configured when the container starts. +Additionally, the image configures an alias in the `.bashrc` to update the kubeconfig with the specified AWS region and EKS cluster name. + +## Features + +- AWS CLI pre-installed +- `kubectl` pre-installed +- Automatic SSO configuration at startup +- Alias for updating kubeconfig with AWS region and EKS cluster + +## Build Arguments + +The Docker image build requires the following arguments: + +- `AWS_REGION`: The AWS region where your EKS cluster is located. +- `EKS_CLUSTER`: The name of your EKS cluster. + +### Build the Docker Image + +To build the Docker image with the required arguments, run: + +```bash +docker build --build-arg AWS_REGION= --build-arg EKS_CLUSTER= -t aws-kubectl . +``` + +### Running the Container + +To run the container, ensure your local `.aws` directory is mounted to the container's `/root/.aws` directory. This allows the container to access your AWS configurations and credentials, including SSO profiles. + +#### Example for Linux/macOS, Windows with WSL, or Git Bash + +```bash +docker run -it --rm -v ~/.aws:/root/.aws aws-kubectl +``` + +#### Example for Windows with PowerShell + +```powershell +docker run -it --rm -v ${env:USERPROFILE}\.aws:/root/.aws aws-kubectl +``` + +### Using the Kubeconfig Alias + +Once the container is running, you can use the configured alias to update your kubeconfig: + +```bash +update-kubeconfig +``` + +This command automatically updates the kubeconfig with the AWS region and EKS cluster name specified during the build. + +### Notes + +- The container must have access to your AWS credentials, so mounting your `.aws` directory is necessary. +- The startup script will check if SSO is configured and prompt you if additional steps are required. + +## Contributing + +Feel free to open issues or submit pull requests if you find any bugs or have suggestions for improvements. + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. diff --git a/entrypoint.sh b/entrypoint.sh index 4b8500e..b3d3799 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,11 +1,11 @@ -#!/bin/bash - -# Check if the 'eks' profile exists -aws configure list-profiles | grep -q '^eks$' -if [ $? -eq 0 ]; then - echo "Profile 'eks' found. Running 'aws sso login --profile eks'." - aws sso login --profile eks -else - echo "Profile 'eks' not found. Running 'aws configure sso'." - aws configure sso +#!/bin/bash + +# Check if the 'eks' profile exists +aws configure list-profiles | grep -q '^eks$' +if [ $? -eq 0 ]; then + echo "Profile 'eks' found. Running 'aws sso login --profile eks'." + aws sso login --profile eks +else + echo "Profile 'eks' not found. Running 'aws configure sso'." + aws configure sso fi \ No newline at end of file