Skip to content

Commit e37cc57

Browse files
feat: publish container image for cli (#11)
Signed-off-by: Mathew Wicks <[email protected]>
1 parent e158fd9 commit e37cc57

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

.github/workflows/publish.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
env:
13+
IMAGE_OWNER: ${{ github.repository_owner }}
14+
IMAGE_TITLE: "cli"
15+
IMAGE_DESCRIPTION: "the CLI for deployKF"
16+
IMAGE_FOLDER: ""
17+
IMAGE_PLATFORMS: |-
18+
linux/amd64
19+
linux/arm64
20+
21+
jobs:
22+
build_and_push_images:
23+
runs-on: ubuntu-latest
24+
## only run if the tag looks like a semver
25+
if: startsWith(github.ref_name, 'v')
26+
steps:
27+
- name: Check out code
28+
uses: actions/checkout@v3
29+
30+
- name: Install QEMU
31+
uses: docker/setup-qemu-action@v2
32+
33+
- name: Install Docker Buildx
34+
uses: docker/setup-buildx-action@v2
35+
36+
- name: Login to GitHub Container Registry
37+
uses: docker/login-action@v2
38+
with:
39+
registry: ghcr.io
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Generate Image Tags/Labels
44+
id: meta
45+
uses: docker/metadata-action@v4
46+
with:
47+
images: |
48+
ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_TITLE }}
49+
flavor: |
50+
latest=auto
51+
tags: |
52+
type=semver,priority=200,pattern={{major}}.{{minor}}
53+
type=semver,priority=100,pattern={{version}}
54+
labels: |
55+
org.opencontainers.image.title=${{ env.IMAGE_TITLE }}
56+
org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }}
57+
org.opencontainers.image.url=https://github.com/${{ github.repository }}/tree/main/${{ env.IMAGE_FOLDER }}
58+
org.opencontainers.image.source=https://github.com/${{ github.repository }}/tree/main/${{ env.IMAGE_FOLDER }}
59+
60+
- name: Build and Push Image
61+
uses: docker/build-push-action@v4
62+
with:
63+
context: ./${{ env.IMAGE_FOLDER }}
64+
build-args: |
65+
DKF_CLI_RELEASE_TAG=${{ github.ref_name }}
66+
push: true
67+
platforms: ${{ env.IMAGE_PLATFORMS }}
68+
tags: ${{ steps.meta.outputs.tags }}
69+
labels: ${{ steps.meta.outputs.labels }}
70+
cache-from: type=registry,ref=ghcr.io/${{ env.IMAGE_OWNER }}/ci/${{ env.IMAGE_TITLE }}
71+
cache-to: type=registry,ref=ghcr.io/${{ env.IMAGE_OWNER }}/ci/${{ env.IMAGE_TITLE }},mode=max

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM alpine:3.18.2
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
# args -- software versions
7+
ARG DKF_CLI_OS=${TARGETOS}
8+
ARG DKF_CLI_ARCH=${TARGETARCH}
9+
ARG DKF_CLI_RELEASE_TAG=v0.1.0
10+
11+
# args -- uid/gid
12+
ARG DEPLOYKF_USER=deploykf
13+
ARG DEPLOYKF_GROUP=deploykf
14+
ARG DEPLOYKF_UID=1001
15+
ARG DEPLOYKF_GID=1001
16+
ARG DEPLOYKF_HOME=/home/${DEPLOYKF_USER}
17+
18+
# install deploykf cli
19+
RUN wget -q -O /tmp/deploykf "https://github.com/deploykf/cli/releases/download/${DKF_CLI_RELEASE_TAG}/deploykf-${DKF_CLI_OS}-${DKF_CLI_ARCH}" \
20+
&& wget -q -O /tmp/deploykf.sha256 "https://github.com/deploykf/cli/releases/download/${DKF_CLI_RELEASE_TAG}/deploykf-${DKF_CLI_OS}-${DKF_CLI_ARCH}.sha256" \
21+
&& echo "$(cat /tmp/deploykf.sha256 | awk '{ print $1; }') /tmp/deploykf" | sha256sum -c - \
22+
&& chmod +x /tmp/deploykf \
23+
&& mv /tmp/deploykf /usr/local/bin/deploykf \
24+
&& rm -rf /tmp/deploykf*
25+
26+
# create non-root 'deploykf' user/group
27+
RUN addgroup -g ${DEPLOYKF_GID} "${DEPLOYKF_GROUP}" \
28+
&& adduser -D -h "${DEPLOYKF_HOME}" -u ${DEPLOYKF_UID} -G ${DEPLOYKF_GROUP} "${DEPLOYKF_USER}"
29+
30+
USER ${DEPLOYKF_UID}:${DEPLOYKF_GID}
31+
WORKDIR ${DEPLOYKF_HOME}
32+
33+
ENTRYPOINT ["/usr/local/bin/deploykf"]

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,35 @@ deploykf \
3030
This command will generate deployKF manifests in the `./GENERATOR_OUTPUT` directory using the `v0.1.0` source version and the values specified in your `./custom-values.yaml` file.
3131
Note that the `--source-version` flag must correspond to a tag from a [deployKF release](https://github.com/deployKF/deployKF/releases).
3232

33+
> __TIP:__
34+
>
35+
> The version of the CLI does NOT need to match the `--source-version` you are generating manifests for.
36+
> If a breaking change is ever needed, the CLI will fail to generate with newer source versions, and will print message telling you to upgrade the CLI.
37+
38+
## Container Image
39+
40+
We publish the `deploykf` CLI as a container image on the following registries:
41+
42+
| Registry | Image | Pull Command |
43+
|---------------------------|--------------------------------------------------------|---------------------------------------------|
44+
| GitHub Container Registry | [`ghcr.io/deploykf/cli`](https://ghcr.io/deploykf/cli) | `docker pull ghcr.io/deploykf/cli:TAG_NAME` |
45+
46+
To use the container image, you need to mount your local filesystem into the container:
47+
48+
```bash
49+
CONTAINER_IMAGE="ghcr.io/deploykf/cli:0.1.1"
50+
51+
docker run \
52+
--rm \
53+
--volume "$(pwd):/home/deploykf" \
54+
--volume "${HOME}/.deploykf:/home/deploykf/.deploykf" \
55+
"${CONTAINER_IMAGE}" \
56+
generate \
57+
--source-version "0.1.0" \
58+
--values ./sample-values.yaml \
59+
--output-dir ./GENERATOR_OUTPUT
60+
```
61+
3362
## Development
3463

3564
Here are some helpful commands when developing the CLI:

RELEASING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ This guide is intended for maintainers who want to make a new release of the dep
1818
- The release will include the binaries and corresponding SHA256 checksums for all supported platforms.
1919
3. Generate the changelog using the "generate release notes" feature of GitHub and set it as the release description.
2020
4. When ready to ship, manually publish the draft release.
21+
- This will trigger a workflow to build and push the Docker images for the release.
2122
5. Update the changelog on the website using the [`update_changelogs.sh`](https://github.com/deployKF/website/blob/main/update_changelogs.sh) script.

0 commit comments

Comments
 (0)