diff --git a/.circleci/config.yml b/.circleci/config.yml index 9a89695d..4f560114 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,102 +1,59 @@ -version: 2 +version: 2.1 + +executors: + docker-executor: + docker: + - image: circleci/python:3.8 + jobs: - # Define in CircleCi Project Variables: $DOCKERHUB_REPO, $DOCKERHUB_USER, $DOCKERHUB_PASS - # Publish jobs require those variables - publish_docker_linuxamd64: - machine: - docker_layer_caching: false + setup-docker-buildx: + executor: docker-executor steps: - - checkout + - setup_remote_docker: + version: 20.10.7 + experimental: true - run: + name: Set up QEMU command: | - LATEST_TAG="${CIRCLE_TAG:1}" - DOCKERHUB_DESTINATION="$DOCKERHUB_REPO:$LATEST_TAG-amd64" - DOCKERHUB_DOCKERFILE="dockerfiles/Dockerfile" - sudo docker login --username=$DOCKERHUB_USER --password=$DOCKERHUB_PASS - sudo docker build --pull -t "$DOCKERHUB_DESTINATION" -f "$DOCKERHUB_DOCKERFILE" . - sudo docker push "$DOCKERHUB_DESTINATION" - no_output_timeout: 25m + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - run: + name: Set up Buildx + command: | + docker buildx create --use + docker buildx inspect --bootstrap - publish_docker_linuxarm32v7: - machine: - docker_layer_caching: false + publish_docker: + executor: docker-executor steps: - - checkout + - setup_remote_docker: + version: 20.10.7 + experimental: true + - checkout - run: + name: Set up QEMU command: | - sudo docker run --rm --privileged multiarch/qemu-user-static:register --reset - LATEST_TAG="${CIRCLE_TAG:1}" - DOCKERHUB_DESTINATION="$DOCKERHUB_REPO:$LATEST_TAG-arm32v7" - DOCKERHUB_DOCKERFILE="dockerfiles/Dockerfile.arm32v7" - sudo docker login --username=$DOCKERHUB_USER --password=$DOCKERHUB_PASS - sudo docker build --pull -t "$DOCKERHUB_DESTINATION" -f "$DOCKERHUB_DOCKERFILE" . - sudo docker push "$DOCKERHUB_DESTINATION" - no_output_timeout: 25m - - publish_docker_linuxarm64v8: - machine: - docker_layer_caching: false - steps: - - checkout + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - run: + name: Set up Buildx command: | - sudo docker run --rm --privileged multiarch/qemu-user-static:register --reset - LATEST_TAG="${CIRCLE_TAG:1}" - DOCKERHUB_DESTINATION="$DOCKERHUB_REPO:$LATEST_TAG-arm64v8" - DOCKERHUB_DOCKERFILE="dockerfiles/Dockerfile.arm64v8" - sudo docker login --username=$DOCKERHUB_USER --password=$DOCKERHUB_PASS - sudo docker build --pull -t "$DOCKERHUB_DESTINATION" -f "$DOCKERHUB_DOCKERFILE" . - sudo docker push "$DOCKERHUB_DESTINATION" - no_output_timeout: 25m - - publish_docker_multiarch: - machine: - enabled: true - image: ubuntu-2004:2022.07.1 - steps: + docker buildx create --use + docker buildx inspect --bootstrap - run: + name: Build and push Docker images command: | - # Turn on Experimental features LATEST_TAG="${CIRCLE_TAG:1}" - sudo mkdir ./.docker - sudo sh -c 'echo "{ \"experimental\": \"enabled\" }" >> ./.docker/config.json' - # - sudo docker login --username=$DOCKERHUB_USER --password=$DOCKERHUB_PASS - # - sudo docker manifest create --amend "$DOCKERHUB_REPO:$LATEST_TAG" "$DOCKERHUB_REPO:$LATEST_TAG-amd64" "$DOCKERHUB_REPO:$LATEST_TAG-arm32v7" "$DOCKERHUB_REPO:$LATEST_TAG-arm64v8" - sudo docker manifest annotate "$DOCKERHUB_REPO:$LATEST_TAG" "$DOCKERHUB_REPO:$LATEST_TAG-amd64" --os linux --arch amd64 - sudo docker manifest annotate "$DOCKERHUB_REPO:$LATEST_TAG" "$DOCKERHUB_REPO:$LATEST_TAG-arm32v7" --os linux --arch arm --variant v7 - sudo docker manifest annotate "$DOCKERHUB_REPO:$LATEST_TAG" "$DOCKERHUB_REPO:$LATEST_TAG-arm64v8" --os linux --arch arm64 --variant v8 - sudo docker manifest push "$DOCKERHUB_REPO:$LATEST_TAG" -p - no_output_timeout: 25m + DOCKERHUB_DESTINATION="$DOCKERHUB_REPO:$LATEST_TAG" + docker login --username=$DOCKERHUB_USER --password=$DOCKERHUB_PASS + docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64/v8 --pull -t "$DOCKERHUB_DESTINATION" -f dockerfiles/Dockerfile --push . workflows: version: 2 publish: jobs: - - publish_docker_linuxamd64: - filters: - branches: - ignore: /.*/ - tags: - only: /v(?:(?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?:([A-Za-z1-9])*))?)$/ - - publish_docker_linuxarm32v7: - filters: - branches: - ignore: /.*/ - tags: - only: /v(?:(?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?:([A-Za-z1-9])*))?)$/ - - publish_docker_linuxarm64v8: - filters: - branches: - ignore: /.*/ - tags: - only: /v(?:(?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?:([A-Za-z1-9])*))?)$/ - - publish_docker_multiarch: + - setup-docker-buildx + - publish_docker: requires: - - publish_docker_linuxamd64 - - publish_docker_linuxarm32v7 - - publish_docker_linuxarm64v8 + - setup-docker-buildx filters: branches: ignore: /.*/ diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml new file mode 100644 index 00000000..1279fe27 --- /dev/null +++ b/.github/workflows/docker-release.yml @@ -0,0 +1,53 @@ +name: Build docker images + +on: + push: + tags: + - '^v[0-9]{2}\.[0-9]{2}(\.[0-9]{1,2})?$' + workflow_dispatch: + inputs: + version: + description: 'Release version' + required: true + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Set up version + id: set-version + run: | + if [ "${{ github.event.inputs.version }}" != "" ]; then + VERSION=${{ github.event.inputs.version }} + elif [ "${{ github.ref_type }}" == "tag" ]; then + VERSION=${{ github.ref_name }} + else + echo "No version provided and no tag found." + exit 1 + fi + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64,linux/arm/v7 + tags: | + shahanafarooqui/rtl:$VERSION diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..84b70670 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,78 @@ +FROM node:18-alpine as base + +WORKDIR /RTL + +COPY package.json /RTL/package.json +COPY package-lock.json /RTL/package-lock.json + +RUN npm install --legacy-peer-deps + +COPY . . + +# Build the Angular application +RUN npm run buildfrontend + +# Build the Backend from typescript server +RUN npm run buildbackend + +# Remove non production necessary modules +RUN npm prune --omit=dev --legacy-peer-deps + +FROM arm32v7/node:18-alpine as runner-arm32v7 + +ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-armel /tini +ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-armel.asc /tini.asc +RUN chmod +x /tini + +WORKDIR /RTL + +COPY --from=base /RTL/rtl.js ./rtl.js +COPY --from=base /RTL/package.json ./package.json +COPY --from=base /RTL/frontend ./frontend +COPY --from=base /RTL/backend ./backend +COPY --from=base /RTL/node_modules/ ./node_modules +COPY --from=base /tini /sbin/tini + +EXPOSE 3000 + +ENTRYPOINT ["/sbin/tini", "-g", "--"] + +CMD ["node", "rtl"] + +FROM arm64v8/node:18-alpine as runner-arm64v8 + +ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-arm64 /tini +RUN chmod +x /tini + +WORKDIR /RTL + +COPY --from=base /RTL/rtl.js ./rtl.js +COPY --from=base /RTL/package.json ./package.json +COPY --from=base /RTL/frontend ./frontend +COPY --from=base /RTL/backend ./backend +COPY --from=base /RTL/node_modules/ ./node_modules +COPY --from=base /tini /sbin/tini + +EXPOSE 3000 + +ENTRYPOINT ["/sbin/tini", "-g", "--"] + +CMD ["node", "rtl"] + +FROM node:18-alpine as runner-amd64 + +RUN apk add --no-cache tini + +WORKDIR /RTL + +COPY --from=base /RTL/rtl.js ./rtl.js +COPY --from=base /RTL/package.json ./package.json +COPY --from=base /RTL/frontend ./frontend +COPY --from=base /RTL/backend ./backend +COPY --from=base /RTL/node_modules/ ./node_modules + +EXPOSE 3000 + +ENTRYPOINT ["/sbin/tini", "-g", "--"] + +CMD ["node", "rtl"] diff --git a/dockerfiles/Dockerfile b/dockerfiles/Dockerfile deleted file mode 100644 index d84ae9af..00000000 --- a/dockerfiles/Dockerfile +++ /dev/null @@ -1,46 +0,0 @@ -# --------------- -# Install Dependencies -# --------------- -FROM node:18-alpine as builder - -WORKDIR /RTL - -COPY package.json /RTL/package.json -COPY package-lock.json /RTL/package-lock.json - -RUN npm install --legacy-peer-deps - -# --------------- -# Build App -# --------------- -COPY . . - -# Build the Angular application -RUN npm run buildfrontend - -# Build the Backend from typescript server -RUN npm run buildbackend - -# Remove non production necessary modules -RUN npm prune --omit=dev --legacy-peer-deps - -# --------------- -# Release App -# --------------- -FROM node:18-alpine as runner - -WORKDIR /RTL - -RUN apk add --no-cache tini - -COPY --from=builder /RTL/rtl.js ./rtl.js -COPY --from=builder /RTL/package.json ./package.json -COPY --from=builder /RTL/frontend ./frontend -COPY --from=builder /RTL/backend ./backend -COPY --from=builder /RTL/node_modules/ ./node_modules - -EXPOSE 3000 - -ENTRYPOINT ["/sbin/tini", "-g", "--"] - -CMD ["node", "rtl"] diff --git a/dockerfiles/Dockerfile.arm32v7 b/dockerfiles/Dockerfile.arm32v7 deleted file mode 100644 index 8ec8d167..00000000 --- a/dockerfiles/Dockerfile.arm32v7 +++ /dev/null @@ -1,49 +0,0 @@ -# --------------- -# Install Dependencies -# --------------- -FROM node:18-alpine as builder - -ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-armel /tini -ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-armel.asc /tini.asc -RUN chmod +x /tini - -WORKDIR /RTL - -COPY package.json /RTL/package.json -COPY package-lock.json /RTL/package-lock.json - -RUN npm install --legacy-peer-deps - -# --------------- -# Build App -# --------------- -COPY . . - -# Build the Angular application -RUN npm run buildfrontend - -# Build the Backend from typescript server -RUN npm run buildbackend - -# Remove non production necessary modules -RUN npm prune --omit=dev --legacy-peer-deps - -# --------------- -# Release App -# --------------- -FROM arm32v7/node:18-alpine as runner - -WORKDIR /RTL - -COPY --from=builder /RTL/rtl.js ./rtl.js -COPY --from=builder /RTL/package.json ./package.json -COPY --from=builder /RTL/frontend ./frontend -COPY --from=builder /RTL/backend ./backend -COPY --from=builder /RTL/node_modules/ ./node_modules -COPY --from=builder "/tini" /sbin/tini - -EXPOSE 3000 - -ENTRYPOINT ["/sbin/tini", "-g", "--"] - -CMD ["node", "rtl"] diff --git a/dockerfiles/Dockerfile.arm64v8 b/dockerfiles/Dockerfile.arm64v8 deleted file mode 100644 index 6b003a12..00000000 --- a/dockerfiles/Dockerfile.arm64v8 +++ /dev/null @@ -1,48 +0,0 @@ -# --------------- -# Install Dependencies -# --------------- -FROM node:18-alpine as builder - -ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-arm64 /tini -RUN chmod +x /tini - -WORKDIR /RTL - -COPY package.json /RTL/package.json -COPY package-lock.json /RTL/package-lock.json - -RUN npm install --legacy-peer-deps - -# --------------- -# Build App -# --------------- -COPY . . - -# Build the Angular application -RUN npm run buildfrontend - -# Build the Backend from typescript server -RUN npm run buildbackend - -# Remove non production necessary modules -RUN npm prune --omit=dev --legacy-peer-deps - -# --------------- -# Release App -# --------------- -FROM arm64v8/node:18-alpine as runner - -WORKDIR /RTL - -COPY --from=builder /RTL/rtl.js ./rtl.js -COPY --from=builder /RTL/package.json ./package.json -COPY --from=builder /RTL/frontend ./frontend -COPY --from=builder /RTL/backend ./backend -COPY --from=builder /RTL/node_modules/ ./node_modules -COPY --from=builder "/tini" /sbin/tini - -EXPOSE 3000 - -ENTRYPOINT ["/sbin/tini", "-g", "--"] - -CMD ["node", "rtl"]