From d8d9df1c54f3a8987b3432231a638cf32c702bb1 Mon Sep 17 00:00:00 2001 From: Max Stanley Date: Tue, 21 Nov 2023 23:30:14 +0000 Subject: [PATCH] Add dockerfile and push to ghcr --- .dockerignore | 20 +++++++++++++ .github/workflows/docker.yml | 57 ++++++++++++++++++++++++++++++++++++ Dockerfile | 26 ++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..c0e6893c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,20 @@ +node_modules +npm-debug.log +travis.log +build +.vscode +.*.swp +src/core/config/modules/* +src/core/config/OperationConfig.json +src/core/operations/index.mjs +src/node/config/OperationConfig.json +src/node/index.mjs +**/*.DS_Store +tests/browser/output/* +.node-version + +.git/ +.github/ +tests/ +.dockerignore +Dockerfile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..17aae1a2 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,57 @@ +name: Docker + +on: + push: + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run tests for all PRs to master. + pull_request: + branches: + - master + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/metadata-action@v5 + if: github.ref_type == 'tag' + id: meta + with: + images: ghcr.io/${{ github.repository }} + # this will generate tags in the following format: + # + # latest + # 1 + # 1.2 + # 1.2.3 + tags: | + type=raw,value=latest + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{version}} + - uses: docker/build-push-action@v5 + if: github.ref_type == 'tag' + with: + context: . + push: true + pull: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - uses: docker/build-push-action@v5 + if: github.ref_type == 'branch' + with: + context: . + push: false + pull: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..9ba461fd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM node:20-alpine3.18 AS cyberchef-build + +ENV NODE_OPTIONS="--max_old_space_size=2048" + +WORKDIR /usr/src/app + +COPY ./Gruntfile.js . +COPY ./webpack.config.js . +COPY ./package.json . +COPY ./package-lock.json . + +RUN npm install + +COPY . . + +RUN npx grunt prod + +RUN unzip build/prod/*.zip + +FROM nginx:1.25-alpine3.18 AS cyberchef + +WORKDIR /usr/share/nginx/html/ + +COPY --from=cyberchef-build /usr/src/app/build/prod/ . + +RUN rm BundleAnalyzerReport.html