Skip to content

Commit

Permalink
Add github action to build and publish docker image
Browse files Browse the repository at this point in the history
Resolves #37.
  • Loading branch information
kezhuw committed Dec 12, 2024
1 parent 3dd4d4e commit cbf3e5c
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
.git/config
45 changes: 45 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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 }}
72 changes: 72 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 72 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/

0 comments on commit cbf3e5c

Please sign in to comment.