initial revision

This commit is contained in:
Jason Swank 2023-12-02 21:16:07 +00:00
commit 009bff7106
11 changed files with 268 additions and 0 deletions

37
.build.yml Normal file
View File

@ -0,0 +1,37 @@
image: alpine/edge
secrets:
- 0ee986ff-5686-43cd-ac3a-1fe5b2e5dd8f
- f523ee29-5ef8-490f-8903-43ad7c49060b
- 130adee5-3a8f-4035-8cad-e3d044be2961
sources:
- https://git.sr.ht/~jswank/alpine-cli
packages:
- podman
- just
- runit
tasks:
# cgroups need to be running in order to run podman
- prep: |
sudo rc-service cgroups start
sleep 1
# build the image using the just recipe
# - sudo (-u root) is required to run podman without more setup
- build: |
cd alpine-cli
sudo --preserve-env just build
# publish the image using the just recipe
# - set environment variables from the ~/.envdir directory. see
# http://smarden.org/runit/chpst.8.html for details on chpst
# - sudo (-u root) is required to run podman without more setup
# - sudo --preserve-env is required to pass environment variables
- publish: |
cd alpine-cli
chpst -e ~/.envdir sudo --preserve-env just registry_pass_var=GH_PAT publish
chpst -e ~/.envdir sudo --preserve-env just registry=docker.io registry_pass_var=DH_PAT publish
chpst -e ~/.envdir sudo --preserve-env just registry=quay.io registry_pass_var=QUAY_PAT publish

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

26
Dockerfile Normal file
View File

@ -0,0 +1,26 @@
FROM public.ecr.aws/amazonlinux/amazonlinux:2023
LABEL org.opencontainers.image.title=jswank/aws-cli \
org.opencontainers.image.description="A minimal image for running AWS CLI " \
org.opencontainers.image.url=https://git.sr.ht/~jswank/aws-cli \
org.opencontainers.image.authors="Jason Swank" \
org.opencontainers.image.licenses=MIT
RUN yum install -y --allowerasing \
coreutils shadow-utils \
less which \
sudo vim-minimal \
aws-cli && \
yum clean all
RUN adduser -r --create-home --shell /bin/bash --groups wheel cli
RUN echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/00-all-wheel-np
COPY --chown=cli:cli home /home/cli
WORKDIR /home/cli
USER cli
CMD ["/bin/bash", "-l"]

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Jason Swank
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

5
NOTICE Normal file
View File

@ -0,0 +1,5 @@
THIRD PARTY SOFTWARE NOTICES AND INFORMATION
Do Not Translate or Localize
This software incorporates material from third parties.
---

77
README.md Normal file
View File

@ -0,0 +1,77 @@
# aws-cli
A minimal image for running the AWS CLI based on Amazon Linux 2023. This is
useful for interactive purposes or as the basis for other utility images.
* [Quickstart](#quickstart)
* [More Info](#more-info)
* [Available Images](#available-images)
* [Helper Script](#helper-script)
* [License](#license)
## Quickstart
```console
$ docker run -ti --rm ghcr.io/jswank/aws-cli:2023
~ $ ^D
exit
$ bin/cli
~ $ ^D
exit
```
## More Info
The image is based on *aws:3*, with a small amount of additional
setup/installation done. See the [Dockerfile](Dockerfile) and [ctx/home](ctx)
for the specifics.
- Some basic utilities are installed for interative and script-based shell usage
- A user is created with sudo (`-u root`) access.
- A few personal preferences are enabled via dotfiles.
## Available Images
See ghcr.io/jswank/aws-cli for current available images.
## Helper Script
A helper script, using [casey/just](https://github.com/casey/just') is in
[bin/cli](bin/cli). It can be used to quickly start an ephemeral (or
persistent) container.
```console
$ bin/cli help
Available recipes:
clean # Remove the persistent container
default # Invoke the 'run' recipe
help recipe="help" # Display this listing. Detailed help is available with 'help recipe_name'.
persist # Run (or attach to) a persistent container
pull # Pull the latest version of the image
restart # Remove a running container, and run the default recipe
run # Run an ephemeral container.
save i=image # Save the running container as a new image
$ bin/cli
~ $ ^D
exit
$ bin/cli persist
~ $ ls
~ $
exit
$ podman cp foo.json cli:/home/cli # copy a file to the persistent container
$ bin/cli persist
~ $ ls
foo.json
~ $ ^D
exit
```
## License
MIT

70
bin/cli Executable file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env -S just --working-directory . --justfile
image := "jswank/aws-cli"
n := "aws-cli"
# Invoke the 'run' recipe
default: run
# Usage: run
#
# Start a shell in an ephemeral container.
#
# Examples:
# cli run
#
# Run an ephemeral container.
@run:
docker run -ti --userns=keep-id --rm {{image}}
# Usage: persist
#
# Start a shell in a persistent container.
#
# Examples:
# cli persist
#
# Run (or attach to) a persistent container
persist:
#!/bin/sh
if [ $(docker ps --all --filter name="^{{n}}$" -q | wc -l) -gt 0 ]; then
docker start -i -a {{n}}
else
docker run -ti --userns=keep-id --name {{n}} {{image}}
fi
# Pull the latest version of the image
@pull:
docker pull {{image}} >/dev/null 2>&1
# Remove the persistent container
@clean:
docker rm -f {{n}} >/dev/null 2>&1
# Usage: save [new_image_name]
#
# Sometimes you want a quick snapshot of your work in progress. Use this target
# to create an image based on the running container.
#
# Examples:
# cli save foo` - saves the current (persistent) container as a new image
# named "foo"
# ` cli save - saves the current (persistent) container as a new
# default image
#
# Save the running container as a new image
save i=image:
docker commit -q {{n}} {{i}} >/dev/null 2>&1
# Remove a running container, and run the default recipe
@restart: clean default
# Display this listing. Detailed help is available with 'help recipe_name'.
help recipe="help":
#!/bin/sh
if [ "{{recipe}}" = "help" ]; then
just --list --justfile {{justfile()}}
else
grep -B 32 -E '^@?{{recipe}}\s?.*:' {{justfile()}} \
| tac | awk 'NR==1 {print; next}; !/^#/{exit}1;' | tac
fi

1
ctx/home/.exrc Normal file
View File

@ -0,0 +1 @@
set tabstop=4

1
ctx/home/.inputrc Normal file
View File

@ -0,0 +1 @@
set editing-mode vi

8
ctx/home/.profile Normal file
View File

@ -0,0 +1,8 @@
export LANG=en_US.UTF-8
export EDITOR=vi
export VISUAL=${EDITOR}
export PAGER=less
export LESS=RX # R for ANSI color sequences, X to not clear screen on exit
export TMPDIR=/var/tmp
export PS1="\w $ "
export PATH=${PATH}:~/.local/bin

21
justfile Normal file
View File

@ -0,0 +1,21 @@
set dotenv-load
tag := `grep ^FROM Dockerfile | cut -d: -f2`
image := "jswank/aws-cli"
registry := "ghcr.io"
registry_user := "jswank"
# this environment variable will be passed to podman login as the password
registry_pass_var := "REGISTRY_PASSWORD"
# build a new image
build flags="":
podman build -t {{image}}:{{tag}} {{flags}} -f Dockerfile ctx
# publish the image
publish alt_tag=tag:
@ podman tag {{image}}:{{tag}} {{registry}}/{{image}}:{{alt_tag}}
@ echo "${{ registry_pass_var }}" | podman login {{registry}} -u {{registry_user}} --password-stdin
@ podman push {{registry}}/{{image}}:{{alt_tag}}
@ podman logout {{registry}}