diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index bc6fd788..5ab109be 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,12 +7,21 @@ on: - master tags: - "v*.*.*" + paths-ignore: + - '**/*.md' + - '.gitignore' + - '.github/**' + - '!.github/workflows/docker.yml' + - 'docker/**' + - '!docker/codex.Dockerfile' + - '!docker/docker-entrypoint.sh' workflow_dispatch: env: DOCKER_FILE: docker/codex.Dockerfile DOCKER_REPO: codexstorage/nim-codex + MAKE_PARALLEL: 4 jobs: @@ -60,7 +69,6 @@ jobs: type=sha,suffix=-${{ env.SUFFIX }},enable=${{ !startsWith(github.ref, 'refs/tags/') }} - name: Docker - Set tags output - if: github.event_name != 'pull_request' id: tags run: | if [[ '${{ matrix.target.os }}' == 'linux' && '${{ matrix.target.arch }}' == 'amd64' ]]; then @@ -70,19 +78,19 @@ jobs: fi - name: Docker - Login to Docker Hub - if: github.event_name != 'pull_request' uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Docker - Build and export to Docker - id: build uses: docker/build-push-action@v4 with: context: . file: ${{ env.DOCKER_FILE }} platforms: ${{ env.PLATFORM }} + build-args: | + MAKE_PARALLEL=${{ env.MAKE_PARALLEL }} load: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} @@ -102,8 +110,6 @@ jobs: REPORT: ${{ steps.slim.outputs.report }} - name: Docker - Push to Docker registry - if: github.event_name != 'pull_request' - id: push uses: docker/build-push-action@v4 with: context: . @@ -116,7 +122,6 @@ jobs: # Publish single image publish: name: Push single image - if: github.event_name != 'pull_request' runs-on: ubuntu-latest needs: build steps: diff --git a/docker/codex.Dockerfile b/docker/codex.Dockerfile index c9a11b02..bd8b3bcf 100644 --- a/docker/codex.Dockerfile +++ b/docker/codex.Dockerfile @@ -1,18 +1,35 @@ -FROM ubuntu:lunar-20230415 AS builder +# Variables +ARG BUILDER=ubuntu:lunar-20230415 +ARG IMAGE=${BUILDER} +ARG BUILD_HOME=/src +ARG MAKE_PARALLEL=${MAKE_PARALLEL:-4} +ARG MAKE_PARAMS=${MAKE_PARAMS:-NIM_PARAMS="-d:disableMarchNative"} +ARG APP_HOME=/codex + +# Build +FROM ${BUILDER} AS builder +ARG BUILD_HOME +ARG MAKE_PARALLEL +ARG MAKE_PARAMS + RUN apt-get update && apt-get install -y git cmake curl make bash lcov build-essential nim RUN echo 'export NIMBLE_DIR="${HOME}/.nimble"' >> "${HOME}/.bash_env" RUN echo 'export PATH="${NIMBLE_DIR}/bin:${PATH}"' >> "${HOME}/.bash_env" -WORKDIR /src +WORKDIR ${BUILD_HOME} COPY . . RUN make clean -RUN make -j4 update -RUN make -j4 NIM_PARAMS="-d:disableMarchNative" +RUN make -j ${MAKE_PARALLEL} update +RUN make -j ${MAKE_PARALLEL} ${MAKE_PARAMS} -FROM ubuntu:lunar-20230415 -WORKDIR /root -RUN apt-get update && apt-get install -y libgomp1 bash -COPY --from=builder /src/build/codex ./ -COPY --from=builder /src/docker/startCodex.sh ./ -RUN chmod +x ./startCodex.sh -CMD ["/bin/bash", "-l", "-c", "./startCodex.sh"] +# Create +FROM ${IMAGE} +ARG BUILD_HOME +ARG APP_HOME + +WORKDIR ${APP_HOME} +COPY --from=builder ${BUILD_HOME}/build/codex /usr/local/bin +COPY --chmod=0755 docker/docker-entrypoint.sh / +RUN apt-get update && apt-get install -y libgomp1 bash && rm -rf /var/lib/apt/lists/* +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["codex"]