-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base-image-n-script - Updated to leverage ubuntu as based image to ma…
…ke it more dynamic and script updated to address the same
- Loading branch information
1 parent
1591a0a
commit ba833b4
Showing
4 changed files
with
118 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,46 @@ | ||
FROM amazon/aws-cli | ||
RUN yum -y update && yum -y updateinfo && yum install -y \ | ||
FROM ubuntu:20.04 | ||
|
||
ENV NVM_DIR /usr/local/nvm | ||
|
||
# Install all dependencies, NVM, GitHub CLI, and other tools in a single RUN command | ||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ | ||
git \ | ||
jq \ | ||
unzip \ | ||
curl \ | ||
wget \ | ||
tar \ | ||
openssl \ | ||
which \ | ||
python3 \ | ||
python3-pip \ | ||
&& git clone https://github.com/tfutils/tfenv.git ~/.tfenv \ | ||
&& curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \ | ||
&& unzip awscliv2.zip \ | ||
&& ./aws/install \ | ||
&& curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \ | ||
&& install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl \ | ||
&& curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 \ | ||
&& chmod 700 get_helm.sh \ | ||
&& sh ./get_helm.sh \ | ||
&& yum upgrade openssl \ | ||
&& pip3 install urllib3==1.26.7 \ | ||
&& pip3 install print-env \ | ||
&& yum clean all | ||
ENV PATH="/root/.tfenv/bin:$PATH" | ||
RUN mkdir /work | ||
&& ./get_helm.sh \ | ||
&& git clone https://github.com/tfutils/tfenv.git ~/.tfenv \ | ||
&& pip3 install urllib3==1.26.7 print-env \ | ||
&& mkdir -p $NVM_DIR \ | ||
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash \ | ||
&& . $NVM_DIR/nvm.sh \ | ||
# Install GitHub CLI | ||
&& curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ | ||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ | ||
&& apt update \ | ||
&& apt install gh \ | ||
# Clean up | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* /awscliv2.zip | ||
|
||
# Set environment path for tfenv and NVM | ||
ENV PATH="/root/.tfenv/bin:$NVM_DIR/versions/node/$(nvm version)/bin:$PATH" | ||
|
||
# Create and set the working directory | ||
WORKDIR /work | ||
|
||
# Copy the script into the container | ||
COPY ./script.sh / | ||
RUN chmod u+x /script.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,44 @@ | ||
### To build your own image | ||
```bash | ||
git clone https://github.com/ashishjullia/docker-dev-awscli.git && cd ansible/single-liner | ||
``` | ||
# Setup | ||
|
||
### Note: This is only required if you are not using portunus | ||
#### Create and ".env" file to pass the secrets | ||
```bash | ||
KEY=VALUE | ||
.........so on | ||
``` | ||
```bash | ||
docker build -t terraform-aws-cli . | ||
``` | ||
```bash | ||
docker image tag terraform-aws-cli ashishjullia19/terraform-aws-cli | ||
``` | ||
###### Note: If you are pushing the image to a private dockerhub repository, make sure to run "docker login" first. | ||
```bash | ||
docker image push ashishjullia19/terraform-aws-cli | ||
``` | ||
### Edit your "~/.bashrc" and place the following "aliases" at the bottom of the file | ||
Create the following function in your `~/.bashrc` and then either: | ||
- logout and login | ||
- `source ~/.bashrc` (I don't prefer this as sometimes it works sometimes it does not) | ||
|
||
```bash | ||
vim ~/.bashrc | ||
``` | ||
function dev() { | ||
local docker_cmd="sudo docker run -it --rm -v $PWD:/work -w /work" | ||
|
||
```bash | ||
alias dev="docker run -it --rm -v $PWD:/work -w /work --env-file=.env --entrypoint /script.sh ashishjullia19/terraform-aws-cli" | ||
# Check for incorrect usage (more than one argument or invalid format) | ||
if [ "$#" -gt 1 ] || ( [ "$#" -eq 1 ] && ! [[ $1 =~ ^.+/+.+$ ]] ); then | ||
echo "Usage: dev [<project-name>/<stage>]" | ||
return 1 | ||
fi | ||
|
||
# Append PORTUNUS_TOKEN if it's set and exactly one correctly formatted argument is provided | ||
if [ -n "$PORTUNUS_TOKEN" ] && [ "$#" -eq 1 ]; then | ||
docker_cmd+=" -e PORTUNUS_TOKEN=${PORTUNUS_TOKEN}/$1" | ||
fi | ||
|
||
docker_cmd+=" --entrypoint /script.sh ashishjullia19/docker-dev-env" | ||
eval $docker_cmd | ||
} | ||
``` | ||
|
||
With portunus integration: | ||
## With portunus integration: | ||
|
||
For `PORTUNUS_TOKEN` make sure to grab this from portunus ui `portunus.ashishjullia.com` and you'll get the token in format: | ||
`PORTUNUS_TOKEN=<TOKEN>/<PORTUNUS_TEAM>/<PORTUNUS_PROJECT>/<PORTUNUS_STAGE>`. Then `<PORTUNUS_TEAM>` will not be same as you'll see in ui, it will be a random value. | ||
By default, you can set the token on your host system under PORTUNUS_TOKEN until `<TOKEN>/<PORTUNUS_TEAM>`, the other parts of the token can be populated inside the container via `.env` file to keep things more dynamic (as once created the `PORTUNUS_TEAM` value remains the same for a user until and unless they are part of other teams as well) OR you can also pass `<PORTUNUS_PROJECT>` `<PORTUNUS_STAGE>` via docker command itself just do `-e <PORTUNUS_PROJECT>=<PORTUNUS_PROJECT>` `-e <PORTUNUS_STAGE>=<PORTUNUS_PROJECT>` | ||
For `.env`, use this: | ||
```bash | ||
PORTUNUS_PROJECT=<value> | ||
PORTUNUS_PROJECT=<value> | ||
``` | ||
```bash | ||
alias dev="docker run -it --rm -v $PWD:/work -w /work --env-file=.env -e PORTUNUS_TOKEN=$PORTUNUS_TOKEN --entrypoint /script.sh ashishjullia19/terraform-aws-cli" | ||
``` | ||
- `PORTUNUS_TOKEN=<TOKEN>/<PORTUNUS_TEAM>/<PORTUNUS_PROJECT>/<PORTUNUS_STAGE>`. Then `<PORTUNUS_TEAM>` will not be same as you'll see in ui, it will be a random value. | ||
- by default, you can set the token on your host system under PORTUNUS_TOKEN until `<TOKEN>/<PORTUNUS_TEAM>`. | ||
|
||
Notes: | ||
- If you run it with just `dev` on terminal then nothing from `script.sh` will be installed/configured | ||
- the utilities specified in the `script.sh` will only work if portunus integration is used and correct key names are used on portunus side that matches to env variables specified in `script.sh` | ||
- to run with portunus integration `dev <portunus-project>/<portunus-stage>` | ||
- if more you specify something like `dev <portunus-project>/<portunus-stage> argument2` -> it will throw error | ||
|
||
```bash | ||
alias dot="source ~/.bashrc" | ||
``` | ||
### Action | ||
###### Run the following commands series in whichever directory you want the docker development environment. | ||
###### Run the following command in whichever directory you want the docker development environment. | ||
|
||
```bash | ||
dot | ||
``` | ||
```bash | ||
dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters