Skip to content

Commit

Permalink
fix "string" comparison in action
Browse files Browse the repository at this point in the history
  • Loading branch information
jabez007 committed Aug 27, 2024
1 parent d9c73f2 commit 51e2788
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .github/shared/docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
136 changes: 68 additions & 68 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
132 changes: 66 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -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=<your-region> --build-arg EKS_CLUSTER=<your-cluster-name> -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=<your-region> --build-arg EKS_CLUSTER=<your-cluster-name> -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.
20 changes: 10 additions & 10 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 51e2788

Please sign in to comment.