Skip to content

Commit 681d80a

Browse files
committed
feat: add gh wf
1 parent 62fa837 commit 681d80a

7 files changed

Lines changed: 391 additions & 125 deletions

File tree

.dockerignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Git & Meta
2+
.git
3+
.github
4+
.gitignore
5+
6+
# Python Bloat
7+
__pycache__
8+
*.pyc
9+
*.pyo
10+
*.pyd
11+
.pytest_cache
12+
.venv
13+
node_modules
14+
15+
# Build Artifacts
16+
dist
17+
build
18+
*.egg-info
19+
20+
# Project Specific
21+
tmp
22+
docs
23+
LICENSE
24+
README.md
25+
Dockerfile*
26+
.env
27+
*.aws/credentials
28+
*.aws/config

.github/workflows/docker.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: 🐳 Reusable Docker Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
required: true
8+
type: string
9+
registry:
10+
required: false
11+
type: string
12+
default: 'docker.io'
13+
image_name:
14+
required: false
15+
type: string
16+
default: ""
17+
push:
18+
required: false
19+
type: boolean
20+
default: true
21+
secrets:
22+
DOCKERHUB_USERNAME:
23+
required: true
24+
DOCKERHUB_TOKEN:
25+
required: true
26+
27+
permissions:
28+
contents: read
29+
packages: write
30+
security-events: write
31+
32+
env:
33+
ORGANISATION: ${{ github.repository_owner }}
34+
35+
36+
jobs:
37+
build:
38+
name: Build Docker Image
39+
runs-on: ubuntu-latest
40+
outputs:
41+
tags: ${{ steps.meta.outputs.tags }}
42+
primary_tag: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
43+
44+
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v4
48+
49+
- name: Resolve Image Name
50+
id: prep
51+
run: |
52+
if [ -n "${{ inputs.image_name }}" ]; then
53+
FULL_NAME="${{ inputs.image_name }}"
54+
else
55+
FULL_NAME="${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}"
56+
fi
57+
58+
# Force lowercase for Docker Hub compatibility
59+
FINAL_NAME=$(echo "$FULL_NAME" | tr '[:upper:]' '[:lower:]')
60+
REPO_ONLY=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]')
61+
62+
echo "image_full_name=$FINAL_NAME" >> $GITHUB_OUTPUT
63+
echo "repo_only=$REPO_ONLY" >> $GITHUB_OUTPUT
64+
65+
echo "ℹ️ Resolved Image Name: $FINAL_NAME"
66+
67+
- name: Log in to ${{ inputs.registry }}
68+
if: github.event_name != 'pull_request'
69+
uses: docker/login-action@v3
70+
with:
71+
registry: ${{ inputs.registry }}
72+
username: ${{ secrets.DOCKERHUB_USERNAME }}
73+
password: ${{ secrets.DOCKERHUB_TOKEN }}
74+
75+
- name: Set up QEMU
76+
uses: docker/setup-qemu-action@v3
77+
with:
78+
platforms: linux/amd64,linux/arm64
79+
80+
- name: Set up Docker Buildx
81+
uses: docker/setup-buildx-action@v3
82+
83+
- name: Generate metadata
84+
id: meta
85+
uses: docker/metadata-action@v5
86+
with:
87+
images: ${{ inputs.registry }}/${{ steps.prep.outputs.image_full_name }}
88+
tags: |
89+
type=semver,pattern={{version}}
90+
type=semver,pattern={{major}}.{{minor}}
91+
type=ref,event=branch
92+
type=raw,value=latest,enable={{is_default_branch}}
93+
type=raw,value=${{ inputs.version }},enable=${{ inputs.version != '' }}
94+
type=sha,prefix=sha-
95+
96+
labels: |
97+
org.opencontainers.image.title=${{ github.event.repository.name }}
98+
org.opencontainers.image.description=${{ github.event.repository.description }}
99+
org.opencontainers.image.vendor=${{ env.ORGANISATION }}
100+
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
101+
org.opencontainers.image.licenses=MIT
102+
103+
- name: Build and push Docker image
104+
uses: docker/build-push-action@v6
105+
with:
106+
context: .
107+
# Multi-arch support
108+
platforms: linux/amd64,linux/arm64
109+
push: true
110+
provenance: false
111+
sbom: true
112+
tags: ${{ steps.meta.outputs.tags }}
113+
labels: ${{ steps.meta.outputs.labels }}
114+
# GitHub Actions Cache (extremely fast)
115+
cache-from: type=gha
116+
cache-to: type=gha,mode=max
117+
118+
- name: Generate image summary
119+
if: github.event_name != 'pull_request'
120+
run: |
121+
echo "## Docker Image Published" >> $GITHUB_STEP_SUMMARY
122+
echo "" >> $GITHUB_STEP_SUMMARY
123+
echo "**Registry:** \`${{ inputs.registry }}\`" >> $GITHUB_STEP_SUMMARY
124+
echo "**Image:** \`${{ steps.prep.outputs.image_full_name }}\`" >> $GITHUB_STEP_SUMMARY
125+
echo "" >> $GITHUB_STEP_SUMMARY
126+
echo "### Tags" >> $GITHUB_STEP_SUMMARY
127+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
128+
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
129+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
130+
echo "" >> $GITHUB_STEP_SUMMARY
131+
echo "### Pull Command" >> $GITHUB_STEP_SUMMARY
132+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
133+
echo "docker pull ${{ inputs.registry }}/${{ steps.prep.outputs.image_full_name }}:latest" >> $GITHUB_STEP_SUMMARY
134+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
135+
136+
- name: Cleanup old Docker Hub tags
137+
uses: data-science-at-scale/delete-docker-hub-tag@v0.6.1
138+
with:
139+
repository: ${{ env.IMAGE_NAME }}
140+
repository: ${{ steps.prep.outputs.repo_only }}
141+
# For Docker Hub, use your username and a Personal Access Token
142+
username: ${{ secrets.DOCKERHUB_USERNAME }}
143+
password: ${{ secrets.DOCKERHUB_TOKEN }}
144+
# Regex for tags to delete (e.g., all except latest and semver)
145+
tag: '^sha-.*$' # Example: delete all git-sha tags

.github/workflows/release.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,19 @@ jobs:
100100
name: ${{ steps.info.outputs.artifact_name }}
101101
path: dist/${{ steps.info.outputs.artifact_name }}
102102

103+
publish-docker:
104+
needs: [check_version]
105+
uses: ./.github/workflows/docker.yml
106+
with:
107+
version: ${{ needs.check_version.outputs.clean_version }}
108+
push: false
109+
secrets:
110+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
111+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
112+
103113
release:
104114
name: Create Release
105-
needs: [build, check_version]
115+
needs: [check_version, build, publish-docker]
106116
env:
107117
VERSION: ${{ needs.check_version.outputs.clean_version }}
108118
runs-on: ubuntu-latest

Dockerfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# --- Stage 1: Builder ---
2+
FROM python:3.11-slim-bookworm AS builder
3+
4+
# This ARG is automatically populated by Buildx
5+
ARG TARGETARCH
6+
7+
# 1. Install build-only dependencies
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
curl \
10+
git \
11+
unzip \
12+
ca-certificates \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
WORKDIR /app
16+
17+
# 2. Install official AWS CLI v2
18+
# Map Docker arch names to AWS CLI arch names
19+
RUN set -eux; \
20+
case "$TARGETARCH" in \
21+
arm64) AWS_ARCH="aarch64" ;; \
22+
amd64) AWS_ARCH="x86_64" ;; \
23+
*) echo "Unsupported arch: $TARGETARCH" && exit 1 ;; \
24+
esac; \
25+
curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-${AWS_ARCH}.zip" -o awscliv2.zip; \
26+
unzip awscliv2.zip; \
27+
./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update; \
28+
rm -rf awscliv2.zip ./aws
29+
30+
# 3. Copy and run your Addons installer
31+
COPY . .
32+
33+
ENV PATH="/root/.local/bin:$PATH"
34+
35+
RUN chmod +x ./tools/installer.sh && \
36+
./tools/installer.sh
37+
38+
# --- Stage 2: Final Runtime ---
39+
FROM python:3.11-slim-bookworm
40+
41+
# 1. Install minimal runtime utilities (needed for AWS CLI output and SSL)
42+
RUN apt-get update && apt-get install -y --no-install-recommends \
43+
groff \
44+
less \
45+
curl \
46+
ca-certificates \
47+
&& rm -rf /var/lib/apt/lists/*
48+
49+
# 2. Copy AWS CLI v2 from builder
50+
COPY --from=builder /usr/local/aws-cli /usr/local/aws-cli
51+
# Instead of copying the symlink, just create a new one in the final stage
52+
RUN ln -s /usr/local/aws-cli/v2/current/bin/aws /usr/local/bin/aws
53+
54+
# 3. Copy your Addons and Alias config from builder
55+
COPY --from=builder /root/.local /root/.local
56+
COPY --from=builder /root/.aws /root/.aws
57+
58+
# 4. Final environment setup
59+
WORKDIR /root
60+
ENV PATH="/root/.local/bin:/usr/local/bin:$PATH"
61+
62+
# Act as a simple app
63+
ENTRYPOINT ["aws"]
64+
CMD ["--help"]

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,10 @@ To build the project from source or add new commands:
107107

108108
```bash
109109
./tools/build.sh
110-
```
110+
```
111+
## Docker
112+
113+
# Example: Check whoami (mounting your local AWS credentials)
114+
```bash
115+
docker run --rm -v ~/.aws:/root/.aws awscli-addons whoami
116+
```

docs/TODO.md

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
- install.sh
2-
<!-- 1. configure correct setup -->
3-
<!-- 2. test it -->
4-
3. write docs
5-
<!-- 4. ADD awscli-aliases -->
6-
7-
- github action workflow
8-
<!-- 1. Create setup -->
9-
<!-- 2. test in tempo repo -->
10-
<!-- 3. Write docs -->
11-
12-
add Docker container to docker hub + repo dockerfile
13-
14-
- python app
15-
1. Add configuration command
16-
<!-- 1. if don;t exist aws-cli -->
17-
<!-- 2. to simplify setup of work station -->
18-
1. Add commands
19-
1. show creads - for curent profile
20-
2. configure - change all configs + creds
21-
3. Add Upgrade app
22-
4. login ecr https://github.com/lamhaison/aws-cli-utils/blob/main/services/ecr.sh
23-
2. add docs
24-
2. Add Windows support
25-
26-
27-
28-
291
## Roadmap
30-
- SSO support
2+
- add Docker container to docker hub + repo dockerfile
3+
<!-- - add docker hub (dh) -->
4+
- add docker to github wf
5+
- add dh to readme
6+
- add docs to dockerhub
7+
8+
- Add configuration command (read alias and add extra)
9+
1. show creads - for curent profile
10+
2. configure - change all configs + creds
11+
3. Add Upgrade app
12+
4. login ecr https://github.com/lamhaison/aws-cli-utils/blob/main/services/ecr.sh
13+
5. docs
14+
15+
- Add documentation
16+
17+
- Add Windows support
18+
3119
- Session caching (Not apply mfa each time)
20+
3221
- Auto-refresh role (same as aws-vault)
22+
3323
- Pipe-friendly output
24+
3425
- TUI mode
26+
3527
- JSON output mode
3628
`awscli-addons whoami --json`
37-
- etc
3829

30+
- SSO support
31+
32+
33+
34+
35+
docker build -t awscli-addons .
3936

37+
# Example: Check whoami (mounting your local AWS credentials)
38+
docker run --rm -v ~/.aws:/root/.aws awscli-addons whoami
39+
docker run --rm -it awscli-addons bash
40+
VERSION=feature/init tools/installer.sh

0 commit comments

Comments
 (0)