Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker image #267

Merged
merged 4 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
client/node_modules/
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Build Client
FROM node:14-alpine as client

RUN apk update && apk --no-cache --virtual build-dependencies add make git bash python3 gcc g++
ADD . /ratel

WORKDIR /ratel
RUN scripts/build.prod.sh --client

# Build Server
FROM golang:1.16-alpine as server

RUN apk update && apk add git bash
ADD . /ratel

WORKDIR /ratel
COPY --from=client /ratel/server/bindata.go server/bindata.go
RUN ./scripts/build.prod.sh --server


# Final Image
FROM alpine:latest

RUN apk add --no-cache ca-certificates && mkdir /ratel
COPY --from=server /ratel/build/ratel /ratel/server
EXPOSE 8000

ENTRYPOINT exec /ratel/server
27 changes: 23 additions & 4 deletions scripts/build.prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pushd "$dir" > /dev/null
# setting metadata and flags
version="$(grep -i '"version"' < "$rootDir/client/package.json" | awk -F '"' '{print $4}')"
flagUploadToS3=false
buildClientFiles=false
buildServerBinary=false
commitID="$(git rev-parse --short HEAD)"
commitINFO="$(git show --pretty=format:"%h %ad %d" | head -n1)"

Expand All @@ -20,6 +22,12 @@ pushd "$dir" > /dev/null
;;
-u | --upload ) flagUploadToS3=true
;;

-c | --client ) buildClientFiles=true
;;

-s | --server ) buildServerBinary=true
;;
esac

shift
Expand All @@ -31,11 +39,22 @@ popd > /dev/null

# cd to the root folder.
pushd "$rootDir" > /dev/null
# build client - production flag set to true
buildClient true

# build server - passing along the production flag and version
buildServer true "$version"
# no flag provided build all
if [ $buildClientFiles = false ] && [ $buildServerBinary = false ]; then
buildClientFiles=true
buildServerBinary=true
fi

if [ $buildClientFiles = true ]; then
# build client - production flag set to true
buildClient true
fi

if [ $buildServerBinary = true ]; then
# build server - passing along the production flag and version
buildServer true "$version"
fi

# uploading to s3 when the flagUploadToS3 flag set to true
if [ $flagUploadToS3 = true ]; then
Expand Down
3 changes: 1 addition & 2 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env sh

# Build client files.
function buildClient {
printf "\n=> Building client files...\n"
Expand Down Expand Up @@ -39,7 +38,7 @@ function doChecks {
installGoBinData
fi

if ! go-bindata 2>&1 | grep -- -fs > /dev/null; then
if ! go-bindata 2>&1 | grep -- -fs > /dev/null; then
echo "You might have the wrong version of go-bindata. Updating now"
installGoBinData
fi
Expand Down