diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..384c2d2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +target/ +.git/config diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..81578a3 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,45 @@ +# Copyright 2023 The SeamDB Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: docker +on: + push: + branches: + - docker + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Login to Docker Hub + if: github.event_name == 'push' && vars.DOCKERHUB_USERNAME + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Generate tag for version + id: generate-tag + if: github.event_name == 'push' && github.ref_type == 'tag' + run: echo "VERSION_TAG=,${{ vars.DOCKERHUB_USERNAME }}/seamdb:$GITHUB_REF_NAME" >> $GITHUB_OUTPUT + - name: Test push + run: echo "${{ github.event_name == 'push' && vars.DOCKERHUB_USERNAME != '' }}" + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: ${{ github.event_name == 'push' && vars.DOCKERHUB_USERNAME != '' }} + tags: ${{ vars.DOCKERHUB_USERNAME || 'unamed' }}/seamdb:latest${{ steps.generate-tag.outputs.VERSION_TAG }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..672a99b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,72 @@ +# Copyright 2023 The SeamDB Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM rust:1-bookworm AS build + +RUN apt update && apt install -y cmake protobuf-compiler clang wget + +ENV ETCD_VERSION=v3.5.17 + +RUN wget https://github.com/etcd-io/etcd/releases/download/$ETCD_VERSION/etcd-$ETCD_VERSION-linux-amd64.tar.gz && \ + mkdir /opt/etcd && \ + tar xvf etcd-$ETCD_VERSION-linux-amd64.tar.gz --strip-components 1 --directory=/opt/etcd + +RUN wget https://dlcdn.apache.org/kafka/3.9.0/kafka_2.13-3.9.0.tgz && \ + mkdir /opt/kafka && \ + tar xvf kafka_2.13-3.9.0.tgz --strip-components 1 --directory=/opt/kafka + +COPY . seamdb + +RUN make -C seamdb release + + +# Final image here +FROM debian:bookworm + +RUN apt update && apt install -y openjdk-17-jdk wget lsof + +COPY --from=build /opt/etcd /opt/etcd +COPY --from=build /opt/kafka /opt/kafka +COPY --from=build /seamdb/target/release/seamdbd /usr/bin/ + +ENV PATH=/opt/kafka/bin:/opt/etcd:$PATH + +# https://kafka.apache.org/quickstart +RUN kafka-storage.sh format --standalone -t `kafka-storage.sh random-uuid` -c /opt/kafka/config/kraft/reconfig-server.properties + +ENV RUST_BACKTRACE=1 RUST_LOG=seamdb=trace + +RUN rm -rf entrypoint.sh && \ + echo "kafka-server-start.sh /opt/kafka/config/kraft/reconfig-server.properties >> /var/log/kafka.log 2>&1 &" >> entrypoint.sh && \ + echo "" >> entrypoint.sh && \ + echo "etcd >> /var/log/etcd.log 2>&1 &" >> entrypoint.sh && \ + echo "" >> entrypoint.sh && \ + echo "until lsof -i :2379 > /dev/null" >> entrypoint.sh && \ + echo "do" >> entrypoint.sh && \ + echo " echo waiting etcd up" >> entrypoint.sh && \ + echo " sleep 1" >> entrypoint.sh && \ + echo "done" >> entrypoint.sh && \ + echo "" >> entrypoint.sh && \ + echo "until lsof -i :9092 > /dev/null" >> entrypoint.sh && \ + echo "do" >> entrypoint.sh && \ + echo " echo waiting kafka up" >> entrypoint.sh && \ + echo " sleep 1" >> entrypoint.sh && \ + echo "done" >> entrypoint.sh && \ + echo "" >> entrypoint.sh && \ + echo "seamdbd --cluster.uri etcd://127.0.0.1:2379/seamdb1 --log.uri kafka://127.0.0.1:9092" >> entrypoint.sh && \ + chmod u+x entrypoint.sh + +EXPOSE 5432 + +CMD ./entrypoint.sh