From 1ec904ec482eab6bc8c0cc744863ea9b16a3e2a0 Mon Sep 17 00:00:00 2001 From: Savio Dias <91362589+Savio629@users.noreply.github.com> Date: Fri, 2 Jun 2023 12:52:56 +0530 Subject: [PATCH] feat: add Dockerfile and its release pipeline (#598) --- .github/workflows/release-docker.yml | 37 ++++++++++++++++++++++++++++ Dockerfile | 24 ++++++++++++++++++ docs/installation.md | 24 ++++++++++++++++++ package.json | 3 ++- 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release-docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml new file mode 100644 index 00000000000..6ebf5b917d4 --- /dev/null +++ b/.github/workflows/release-docker.yml @@ -0,0 +1,37 @@ +name: Release Docker Image +on: + release: + types: + - published +jobs: + + publish-docker: + name: Generating Docker + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Get version without v character + id: version + run: | + VERSION=${{github.event.release.tag_name}} + VERSION_WITHOUT_V=${VERSION:1} + echo "value=${VERSION_WITHOUT_V}" >> $GITHUB_OUTPUT + + - name: Release to Docker + run: | + echo ${{secrets.DOCKER_PASSWORD}} | docker login -u ${{secrets.DOCKER_USERNAME}} --password-stdin + npm run docker:build + docker tag asyncapi/cli:latest asyncapi/cli:${{ steps.version.outputs.value }} + docker push asyncapi/cli:${{ steps.version.outputs.value }} + docker push asyncapi/cli:latest + + - name : Sync README.md and Description to Docker Hub + uses: actions/checkout@master + + - uses: meeDamian/sync-readme@v1.0.6 + with: + user: ${{secrets.DOCKER_USERNAME}} + pass: ${{ secrets.DOCKER_PASSWORD }} + slug: asyncapi/cli + description: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..1e1ad3adc07 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM node:16-alpine + +# Create a non-root user +RUN addgroup -S myuser && adduser -S myuser -G myuser + +WORKDIR /app + +# Since 0.14.0 release of html-template chromium is needed for pdf generation +ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium-browser +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true +# Since 0.30.0 release Git is supported and required as a dependency +# Since 0.14.0 release of html-template chromium is needed for pdf generation. +# More custom packages for specific template should not be added to this dockerfile. Instead, we should come up with some extensibility solution. +RUN apk --update add git chromium && \ + rm -rf /var/lib/apt/lists/* && \ + rm /var/cache/apk/* + +# Installing latest released npm package +RUN npm install --ignore-scripts -g @asyncapi/cli + +# Switch to the non-root user +USER myuser + +ENTRYPOINT [ "asyncapi" ] \ No newline at end of file diff --git a/docs/installation.md b/docs/installation.md index 80d0b52d483..c3bdf6aba64 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -25,6 +25,30 @@ After installing Node.js and NPM, run the following command to install the Async ```sh npm install -g @asyncapi/cli ``` +## Docker + +Install [Docker](https://docs.docker.com/get-docker/) first, then use docker to build the image using the following command : +``` +docker build -t asyncapi/cli:latest . +``` +and run the image using the following command : + +```bash +docker run --rm -it \ +--user=root \ +-v [ASYNCAPI SPEC FILE LOCATION]:/app/asyncapi.yml \ +-v [GENERATED FILES LOCATION]:/app/output \ +asyncapi/cli [COMMAND HERE] + +# Example that you can run inside the cli directory after cloning this repository. First, you specify the mount in the location of your AsyncAPI specification file and then you mount it in the directory where the generation result should be saved. +docker run --rm -it \ + --user=root \ + -v ${PWD}/test/fixtures/asyncapi_v1.yml:/app/asyncapi.yml \ + -v ${PWD}/output:/app/output \ + asyncapi/cli generate fromTemplate -o /app/output /app/asyncapi.yml @asyncapi/html-template --force-write +``` +Note: Use ``` ` ``` instead of `\` for Windows. + ## Mac There are two ways to install the AsyncAPI CLI on your macOS: using the `brew` package manager or `pkg` files. diff --git a/package.json b/package.json index d1348af3b74..aa6975829c9 100644 --- a/package.json +++ b/package.json @@ -155,6 +155,7 @@ "build": "rimraf lib && node scripts/fetch-asyncapi-example.js && tsc && echo \"Build Completed\"", "bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION", "dev": "tsc --watch", + "docker:build": "docker build -t asyncapi/cli:latest .", "generate:readme:create": "printf '\n\n# Usage\n\n\n\n# Commands\n\n\n' > scripts/README.md", "generate:readme:commands": "npm run build && cd scripts && DEBUG=* oclif readme", "generate:assets": "npm run generate:readme:toc && npm run generate:commands", @@ -177,4 +178,4 @@ "get-version": "echo $npm_package_version" }, "types": "lib/index.d.ts" -} +} \ No newline at end of file