Skip to content

Commit

Permalink
reworking docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Apr 18, 2018
1 parent d52b278 commit 84abbfb
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 86 deletions.
15 changes: 11 additions & 4 deletions build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pushd ${GOHOME}chat > /dev/null
version=`git tag | tail -1`
version=${version#?}

# Prepare directory for the new release
rm -fR ./releases/${version}
mkdir ./releases/${version}

for plat in "${goplat[@]}"
do
for arc in "${goarc[@]}"
Expand Down Expand Up @@ -64,10 +68,10 @@ do
cp $GOPATH/bin/keygen.exe ./releases/tmp

# Remove possibly existing archive.
rm -f ./releases/tinode-${dbtag}."${version}.${plat}-${arc}".zip
rm -f ./releases/${version}/tinode-${dbtag}."${plat}-${arc}".zip
# Generate a new one
pushd ./releases/tmp > /dev/null
zip -q -r ../tinode-${dbtag}."${version}.${plat}-${arc}".zip ./*
zip -q -r ../${version}/tinode-${dbtag}."${plat}-${arc}".zip ./*
popd > /dev/null
else
# Copy binaries
Expand All @@ -76,12 +80,15 @@ do
cp $GOPATH/bin/keygen ./releases/tmp

# Remove possibly existing archive.
rm -f ./releases/tinode-${dbtag}."${version}.${plat}-${arc}".tar.gz
rm -f ./releases/${version}/tinode-${dbtag}."${plat}-${arc}".tar.gz
# Generate a new one
tar -C ${GOHOME}chat/releases/tmp -zcf ./releases/tinode-${dbtag}."${version}.${plat}-${arc}".tar.gz .
tar -C ${GOHOME}chat/releases/tmp -zcf ./releases/${version}/tinode-${dbtag}."${plat}-${arc}".tar.gz .
fi
done
done
done

# Clean up temporary files
rm -fR ./releases/tmp

popd > /dev/null
37 changes: 37 additions & 0 deletions docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Build and publish Tinode docker images

for line in $@; do
eval "$line"
done

tag=${tag#?}

if [ -z "$tag" ]; then
echo "Must provide tag as 'tag=v1.2.3'"
exit 1
fi

ver=( ${tag//./ } ) # replace points, split into array

# Build a docker image
docker build --build-arg TARGET_DB=rethinkdb --tag tinode-rethinkdb \
--tag tinode/tinode-rethinkdb:latest \
--tag tinode/tinode-rethinkdb:"${ver[0]}.${ver[1]}.${ver[2]}" \
--tag tinode/tinode-rethinkdb:"${ver[0]}.${ver[1]}" docker/tinode

# Deploy tagged images
docker push tinode/tinode-rethinkdb:latest
docker push tinode/tinode-rethinkdb:"${ver[0]}.${ver[1]}.${ver[2]}"
docker push tinode/tinode-rethinkdb:"${ver[0]}.${ver[1]}"


docker build --build-arg TARGET_DB=mysql --tag tinode-mysql \
--tag tinode/tinode-mysql:latest \
--tag tinode/tinode-mysql:"${ver[0]}.${ver[1]}.${ver[2]}" \
--tag tinode/tinode-mysql:"${ver[0]}.${ver[1]}" docker/tinode

docker push tinode/tinode-mysql:latest
docker push tinode/tinode-mysql:"${ver[0]}.${ver[1]}.${ver[2]}"
docker push tinode/tinode-mysql:"${ver[0]}.${ver[1]}"
75 changes: 0 additions & 75 deletions docker/tinode-server/Dockerfile

This file was deleted.

64 changes: 64 additions & 0 deletions docker/tinode/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Docker file builds an image with a tinode chat server.
# The server exposes port 18080.
# In order to run the image you have to link it to a running RethinkDB container
# (assuming it's named 'rethinkdb') and map the port where the tinode server accepts connections:
#
# $ docker run -p 6060:18080 -d --link rethinkdb \
# --env UID_ENCRYPTION_KEY=base64+encoded+16+bytes= \
# --env API_KEY_SALT=base64+encoded+32+bytes \
# --env AUTH_TOKEN_KEY=base64+encoded+32+bytes \
# tinode-server

FROM alpine:3.7

ARG VERSION=0.14.4
ENV VERSION=$VERSION

LABEL maintainer="Gene Sokolov <gene@tinode.co>"
LABEL name="TinodeChatServer"
LABEL version=$VERSION

# Builds for RethinkDB by default. Alternatively use `--build-arg TARGET_DB=mysql` to build for MySQL.
ARG TARGET_DB=rethinkdb
ENV TARGET_DB=$TARGET_DB

# Various encryption and salt keys. Replace with your own in production.

# Key to initialize UID generator
ENV UID_ENCRYPTION_KEY=la6YsO+bNX/+XIkOqc5Svw==

# Key to sign API app ID.
ENV API_KEY_SALT=T713/rYYgW7g4m3vG6zGRh7+FM1t0T8j13koXScOAj4=

# Key used to sign authentication tokens.
ENV AUTH_TOKEN_KEY=wfaY2RgF2S1OQI/ZlK+LSrp1KB2jwAdGAIHQ7JZn+Kc=

# Disable chatbot plugin by default.
ENV PLUGIN_PYTHON_CHAT_BOT_ENABLED=false

# Adding bash and grep as they are used here.
RUN apk add --no-cache bash grep

WORKDIR /opt/tinode

ADD https://github.com/tinode/chat/releases/download/v$VERSION/tinode-$TARGET_DB.linux-amd64.tar.gz .

RUN tar -xzf tinode-$TARGET_DB.linux-amd64.tar.gz

# Copy config template to the container.
COPY config.template .
COPY entrypoint.sh .

# Directory for chatbot data
RUN mkdir /botdata

# Make scripts runnable
RUN chmod +x entrypoint.sh
RUN chmod +x credentials.sh

# Generate config from template and run the server.
ENTRYPOINT ./entrypoint.sh

# HTTP and gRPC ports
EXPOSE 18080 16061

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Ensure the old config is removed
rm -f /config
rm -f working.config

# Generate a new config from template and environment
while IFS='' read -r line || [[ -n $line ]] ; do
Expand All @@ -10,19 +10,19 @@ while IFS='' read -r line || [[ -n $line ]] ; do
RHS="$(eval echo "\"$LHS\"")"
line=${line//$LHS/$RHS}
done
echo "$line" >> /config
done < /config.template
echo "$line" >> working.config
done < config.template


# Initialize the database if it has not been initialized yet
if [ ! -f /botdata/.tn-cookie ]; then
# Run the generator. Save stdout to to a file to extract Tino's password for possible later use.
/go/bin/tinode-db --reset --config=/config --data=/go/src/github.com/tinode/chat/tinode-db/data.json | grep "usr;tino;" > /botdata/tino-password
./init-db --reset --config=working.config --data=data.json | grep "usr;tino;" > /botdata/tino-password

# Convert Tino's authentication credentials into a cookie file.
# The cookie file is also used to check if database has been initialized.
/go/src/github.com/tinode/chat/tinode-db/credentials.sh < /botdata/tino-password > /botdata/.tn-cookie
./credentials.sh < /botdata/tino-password > /botdata/.tn-cookie
fi

# Run the tinode server.
/go/bin/server --config=/config --static_data=/go/example-react-js 2> log.txt
./tinode --config=working.config --static_data=example-react-js 2> /var/log/tinode.log
2 changes: 1 addition & 1 deletion server/auth/token/auth_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (ta *authenticator) GenSecret(rec *auth.Rec) ([]byte, time.Time, error) {
Expires: uint32(expires.Unix()),
AuthLevel: uint16(rec.AuthLevel),
SerialNumber: uint16(ta.serialNumber),
Features: 0,
Features: uint16(rec.Features),
}
buf := new(bytes.Buffer)
binary.Write(buf, binary.LittleEndian, &tl)
Expand Down

0 comments on commit 84abbfb

Please sign in to comment.