From 6904224eb1697e01f9a094b0925382fc3737b1e2 Mon Sep 17 00:00:00 2001 From: Sayan Nandan Date: Wed, 6 Dec 2023 01:07:32 +0530 Subject: [PATCH] Fix Docker images --- .dockerignore | 3 ++- .github/workflows/docker-image.yml | 17 ++++++++--------- Dockerfile | 14 ++++++++------ pkg/docker/start-server.sh | 22 ++++++++++++++++++++++ 4 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 pkg/docker/start-server.sh diff --git a/.dockerignore b/.dockerignore index 4cec9f56..73b3870e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,5 @@ # Only include the skyd binary !target/release/skyd !target/release/skysh -!examples/config-files/docker.toml \ No newline at end of file +!examples/config-files/dpkg/config.yaml +!pkg/docker/start-server.sh \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 8249413f..a972a9d9 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,11 +2,8 @@ name: Docker image on: push: - # Publish `next` as Docker `latest` image. branches: - next - - # Publish `v1.2.3` tags as releases. tags: - v* @@ -34,14 +31,16 @@ jobs: command: build args: --release - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME - if: env.BUILD == 'true' || github.event_name == 'create' && startsWith(github.ref, 'refs/tags/v') + run: docker build . --file Dockerfile --tag $IMAGE_NAME:${{ github.ref == 'refs/heads/next' && 'next' || github.ref_name }} + if: github.ref == 'refs/heads/next' || startsWith(github.ref, 'refs/tags/v') - name: Push to Docker Hub uses: docker/build-push-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - repository: skytable/sdb - tags: latest - tag_with_ref: true - if: env.BUILD == 'true' || github.event_name == 'create' && startsWith(github.ref, 'refs/tags/v') + repository: skytable/skytable + tags: | + ${{ github.ref == 'refs/heads/next' && 'next' || '' }} + ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || '' }} + ${{ startsWith(github.ref, 'refs/tags/v') && 'latest' || '' }} + if: github.ref == 'refs/heads/next' || startsWith(github.ref, 'refs/tags/v') diff --git a/Dockerfile b/Dockerfile index 03820a3b..c58a8ce8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,16 @@ -# # The Dockerfile for the Skytable server sdb -# FROM debian:stable - +# Copy the necessary binaries COPY target/release/skyd /usr/local/bin COPY target/release/skysh /usr/local/bin -RUN mkdir /etc/skytable +# Create necessary directories RUN mkdir /var/lib/skytable -COPY examples/config-files/docker.toml /etc/skytable/skyd.toml +COPY examples/config-files/dpkg/config.yaml /var/lib/skytable/config.yaml +COPY pkg/docker/start-server.sh /usr/local/bin/start-server.sh WORKDIR /var/lib/skytable -CMD ["skyd", "-c", "/etc/skytable/skyd.toml"] +# Install uuidgen for generating a random password +RUN apt-get update && apt-get install -y uuid-runtime +RUN chmod +x /usr/local/bin/start-server.sh +ENTRYPOINT ["/usr/local/bin/start-server.sh"] EXPOSE 2003/tcp diff --git a/pkg/docker/start-server.sh b/pkg/docker/start-server.sh new file mode 100644 index 00000000..6f16923f --- /dev/null +++ b/pkg/docker/start-server.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +CONFIG_FILE="/var/lib/skytable/config.yaml" +PASSWORD_MARKER="rootpass" +IP_MARKER="127.0.0.1" + +generate_password() { + uuidgen | cut -c -16 +} + +sed -i "s/$IP_MARKER/0.0.0.0/g" "$CONFIG_FILE" + +if grep -q "$PASSWORD_MARKER" "$CONFIG_FILE"; then + # Password not set, generate a new one + PASSWORD=$(generate_password) + sed -i "s/$PASSWORD_MARKER/$PASSWORD/g" "$CONFIG_FILE" + echo "Generated Password: $PASSWORD" +else + echo "Using existing password in config file" +fi + +exec skyd --config "$CONFIG_FILE"