diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000000..48b43900f4 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,57 @@ +name: Docker + +on: + push: + # Publish `master` as Docker `latest` image. + branches: + - master + - Dockerfile-with-github-actions + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run tests for any PRs. + pull_request: + +env: + # TODO: Change variable to your image's name. + IMAGE_NAME: iverilog + +jobs: + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + push: + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: docker build --build-arg GITHUB_WORKSPACE=$GITHUB_WORKSPACE . --file Dockerfile --tag $IMAGE_NAME + + - name: Log into registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin + + - name: Push images + run: | + IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..4da0d4c567 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,84 @@ +ARG IMAGE="alpine:3.12" +# Note that some commands such as 'apk add' won't work in arbitrary images. For instance, +# 'apk add' works fine under alpine, but not under Ubuntu (at least not by default.) +# In other words, the following 'apk add' sections assume an alpine based image or a derivitive + +FROM $IMAGE as base + +RUN apk add --no-cache \ + bzip2 \ + libbz2 \ + libgcc \ + libhistory \ + libstdc++ \ + readline \ + zlib + +FROM base as builder + +RUN apk add --no-cache \ + autoconf \ + build-base \ + bison \ + bzip2-dev \ + flex \ + git \ + gperf \ + readline-dev \ + zlib-dev + +COPY . . + +RUN sh autoconf.sh && \ + ./configure && \ + make && \ + make install + +FROM builder as builder-iverilog-regression-test + +RUN make check + +ARG REGRESSION_TEST_URL=https://github.com/steveicarus/ivtest.git +RUN git clone ${REGRESSION_TEST_URL} ivtest + +# Running the tests here was useful for troubleshooting, but we also run them below +# in a lighter weight image so it is not necessary to run them here anymore +# WORKDIR ivtest +# RUN perl vvp_reg.pl +# RUN perl vpi_reg.pl + +FROM base as release-candidate + +COPY --from=builder /usr/local /usr/local/ + +FROM release-candidate as iverilog-vpi + +RUN apk add --no-cache \ + build-base + +FROM iverilog-vpi as test-iverilog-vpi + +RUN apk add --no-cache \ + perl + +COPY --from=builder-iverilog-regression-test /ivtest /ivtest + +WORKDIR /ivtest +RUN perl vvp_reg.pl +RUN perl vpi_reg.pl + +FROM release-candidate as iverilog +# +# Below are some sample commands to build docker images. +# +# The vpi_reg.pl script wont run in this 87.5 MB image which does not contain perl or c/c++ +# docker build . -t iverilog +# +# This is a larger 298 MB image with c/c++ compilers through build-base +# docker build --target iverilog-vpi . -t iverilog-vpi +# +# This is a larger 343 MB image with c/c++ compilers throubh build-base and perl +# docker build --target test-iverilog-vpi . -t iverilog-perl +# +# This is a larger 598 MB image with full featured compiler, git, and full build results +# docker build --target builder . -t iverilog-builder \ No newline at end of file diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu new file mode 100644 index 0000000000..d7002a96ff --- /dev/null +++ b/Dockerfile.ubuntu @@ -0,0 +1,99 @@ +ARG IMAGE="ubuntu:18.04" +# Note that some commands such as 'apk add' won't work in arbitrary images. For instance, +# 'apt-get' works fine under ubuntu, but not under alpine (at least not by default.) +# In other words, the following 'apt-get' sections assume a debian based image or a derivitive + +FROM $IMAGE as base + +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt-get -y update && \ + apt-get install -y \ + make && \ + rm -rf /var/lib/apt/lists/* + +FROM base as builder + +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt-get -y update && \ + apt-get install -y \ + autoconf \ + automake \ + bison \ + build-essential \ + flex \ + git \ + gperf + +COPY . . + +RUN bash autoconf.sh && \ + ./configure && \ + make && \ + make install + +FROM builder as builder-iverilog-regression-test + +RUN make check + +ARG REGRESSION_TEST_URL=https://github.com/steveicarus/ivtest.git +RUN git clone ${REGRESSION_TEST_URL} ivtest + +# Running the tests here was useful for troubleshooting, but we also run them below +# in a lighter weight image so it is not necessary to run them here anymore +# WORKDIR ivtest +# RUN perl vvp_reg.pl +# RUN perl vpi_reg.pl + +FROM base as release-candidate + +COPY --from=builder /usr/local /usr/local/ + +FROM release-candidate as iverilog-vpi + +RUN apt-get update && \ + apt-get install -y \ + build-essential + +FROM iverilog-vpi as test-iverilog-vpi + +RUN apt-get update && \ + apt-get install -y \ + perl + +COPY --from=builder-iverilog-regression-test /ivtest /ivtest + +WORKDIR /ivtest +RUN perl vvp_reg.pl +RUN perl vpi_reg.pl + +FROM release-candidate as iverilog +# +# Below are some sample commands to build docker images. +# +# The vpi_reg.pl script wont run in this 121 MB image which does not contain perl or c/c++ +# docker build -f Dockerfile.ubuntu . -t iverilog +# +# This is a larger 364 MB image with c/c++ compilers through build-essential +# docker build -f Dockerfile.ubuntu --target iverilog-vpi . -t iverilog-vpi +# +# This is a larger 382 MB image with c/c++ compilers throubh build-essential and perl +# docker build -f Dockerfile.ubuntu --target test-iverilog-vpi . -t iverilog-perl +# +# This is a larger 665 MB image with full featured compiler, git, and full build results +# docker build -f Dockerfile.ubuntu --target builder . -t iverilog-builder +# +# Below are some sample commands to build using ubuntu:20.04 as a base image +# +# The vpi_reg.pl script wont run in this 154 MB image which does not contain perl or c/c++ +# docker build -f Dockerfile.ubuntu --build-arg IMAGE="ubuntu:20.04" . -t iverilog +# +# This is a larger 428 MB image with c/c++ compilers through build-essential +# docker build -f Dockerfile.ubuntu --build-arg IMAGE="ubuntu:20.04" --target iverilog-vpi . -t iverilog-vpi +# +# This is a larger 445 MB image with c/c++ compilers throubh build-essential and perl +# docker build -f Dockerfile.ubuntu --build-arg IMAGE="ubuntu:20.04" --target test-iverilog-vpi . -t iverilog-perl +# +# This is a larger 812 MB image with full featured compiler, git, and full build results +# docker build -f Dockerfile.ubuntu --build-arg IMAGE="ubuntu:20.04" --target builder . -t iverilog-builder \ No newline at end of file