diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..53d30e7 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,60 @@ +name: Docker + +on: + push: + branches: + - main + paths: + - 'Dockerfile' + - 'entrypoint.sh' + - '.github/workflows/docker.yaml' + tags: + - "v*" + pull_request: + branches: + - main + paths: + - 'Dockerfile' + - 'entrypoint.sh' + - '.github/workflows/docker.yaml' + +permissions: + contents: read + packages: write + +jobs: + push: + runs-on: ubuntu-latest + steps: + - name: 'git:checkout' + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: "docker:meta" + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + flavor: latest=true + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + - name: "docker:login:ghcr.io" + if: github.ref_type == 'tag' + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GHCR_TOKEN }} + - name: "docker:buildx" + uses: docker/setup-buildx-action@v2 + - name: "docker:build-push" + uses: docker/build-push-action@v3 + with: + context: . + file: Dockerfile + push: ${{ github.ref_type == 'tag' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..5a9ab23 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,7 @@ +# This is a comment. +# Each line is a file pattern followed by one or more owners. + +# These owners will be the default owners for everything in the repo. +# Unless a later match takes precedence, @cebidhem +# will be requested for review when someone opens a pull request. +* @cebidhem diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..62d49e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM alpine:3.18 as base +RUN apk add --no-cache curl openssl +RUN addgroup -g 1001 app && \ + adduser -D -G app -u 1001 app + +FROM base as builder +ENV KUBECTL_VERSION=1.26.4 +ARG TARGETPLATFORM +RUN curl -LO https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/${TARGETPLATFORM}/kubectl && \ + chmod +x ./kubectl && \ + curl -LO https://run.linkerd.io/install && \ + chmod +x ./install && \ + sh install + +FROM base as final +COPY --chown=app:app --from=builder kubectl /usr/local/bin/kubectl +COPY --chown=app:app --from=builder /root/.linkerd2/bin/linkerd /usr/local/bin/linkerd +ADD --chown=app:app entrypoint.sh /app/entrypoint.sh +WORKDIR /app +USER app +ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index f08a981..60cb18d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ # linkerd-sp-swagger-sync + Applying Linkerd ServiceProfiles generated from Swagger automatically + +### Goal + +Linkerd allows to create ServiceProfiles from a Swagger file. This is great when you can generate it locally, or include it somehow in your deployments (Helm, Flux, etc...) + +In my case, I want to reconfigure the ServiceProfile of my backends each time I deploy it in Kubernetes, without wondering if my routes have been updated this time or not. Obviously, several version live at the same time in different clusters, I just don't want to track that. + +This docker image aims at getting a Swagger documentation online, process it with linkerd commands to generate the ServiceProfile and apply it in cluster. + +In my case, I'll run it as a Helm post-upgrade hook. + +### Non Goals + +This fulfills a very specific use-case and yours may be different. If your contributions are welcomed, please note that this is a side project that I'll maintain on my free time on a best effort basis. + +Of course, feel also free to fork the project: it's under the [MIT license](LICENSE). + +### How to run it ? + +Work In Progress diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..cd3202f --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +SWAGGER_URL=$1 +SERVICE=$2 + +curl "${SWAGGER_URL}" | linkerd profile --open-api - "${SERVICE}" | kubectl apply -f - \ No newline at end of file