-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Related to issue #83: Added support for container image #105
Changes from all commits
27c78d0
b5d9eb4
a97436f
2a2e319
61c6384
a3c90fc
3a94cb2
b4c8c56
35477b5
f83b52f
5ce468f
2908212
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Create and publish Docker image | ||
|
||
on: | ||
push: | ||
branches: ['main'] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
permissions: | ||
contents: read | ||
packages: write | ||
# | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. | ||
- name: Log in to the Container registry | ||
uses: docker/login-action | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. | ||
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. | ||
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this, I'm a bit opinionated, but four versions should be released if, say, we're releasing version
This is because this repo tries to follow Semver, so people that need the guarantee that no major breaking change appear in a minor change can confidently pull the newer version of the image. If I ever do, that's on me, not on the people maintaining these apps deployed to environments. I do something similar here: https://github.com/patrickdappollonio/http-server/pkgs/container/docker-http-server although with no minor version, just major and patch, and this has proven to work in corporate environments where that stability can be called out during usage. |
||
labels: ${{ steps.meta.outputs.labels }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.history |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
## Go builder image | ||
FROM golang:1.22 as builder | ||
|
||
ENV GOPATH=/usr/local/go/bin | ||
|
||
WORKDIR /go | ||
|
||
COPY . . | ||
|
||
RUN CGO_ENABLED=0 go build -ldflags "-s" -a -installsuffix cgo . | ||
|
||
## Base image for production usage | ||
FROM alpine:3.14 as production | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be the somewhat biggest showstopper. I would be tempted to use Without this project gathering metrics on its own and based purely on experience reports I've received over the years, as well as looking at the usage of Another thing IMHO I would do here would be to have the image include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What use case do you find that necessary to do? |
||
|
||
COPY --from=builder /go/kubectl-slice /usr/bin/kubectl-slice | ||
|
||
WORKDIR /workdir | ||
|
||
## add user k8s to run the slice tool | ||
RUN set -eux; \ | ||
addgroup -g 1000 k8s; \ | ||
adduser -u 1000 -G k8s -s /bin/sh -h /home/k8s -D k8s | ||
|
||
RUN chown -R k8s:k8s /workdir | ||
|
||
USER k8s | ||
|
||
CMD ["/bin/sh", "-c"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Running in docker | ||
|
||
Run the Docker image from `gchr.io/patrickdappollonio/kubectl-slice` | ||
|
||
## Usage | ||
The container is build to execute both interactive and inline. | ||
|
||
### Interactive shell | ||
|
||
Example, this will start the container in the `/workdir` directory. | ||
```sh | ||
docker run --rm -it \ | ||
gchr.io/patrickdappollonio/kubectl-slice /bin/sh | ||
``` | ||
|
||
### Inline | ||
|
||
**Example 1:** | ||
This will split the `ingress-namespace.yaml` file in the directory `${PWD}/slice/testdata`. | ||
|
||
```sh | ||
docker run --rm -v \ | ||
"${PWD}/slice/testdata":/workdir gchr.io/patrickdappollonio/kubectl-slice \ | ||
kubectl-slice -f ingress-namespace.yaml -o ./ | ||
``` | ||
|
||
**Example 2:** | ||
To display the `kubectl-slice` help. | ||
|
||
```sh | ||
docker run --rm -v \ | ||
"${PWD}/slice/testdata":/workdir gchr.io/patrickdappollonio/kubectl-slice \ | ||
kubectl-slice -h | ||
``` | ||
|
||
**Example 3:** | ||
Statements to `kubectl-slice` can be wrapped in `""` if the commandline escapes unintentionally. | ||
|
||
```sh | ||
docker run --rm -v \ | ||
"${PWD}/slice/testdata":/workdir gchr.io/patrickdappollonio/kubectl-slice \ | ||
kubectl-slice "-h" | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to have a way to test building (but not releasing) the container for commits, so people know nothing breaks on the container side whenever they propose a change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need to investigate on that part