Bel LaPointe 2023-04-10 11:03:25 -06:00
parent c8f015930e
commit 41c9625598
4 changed files with 51 additions and 25 deletions

0
.gitattributes vendored Normal file → Executable file
View File

0
.gitignore vendored Normal file → Executable file
View File

0
build_go_exec Normal file → Executable file
View File

76
do.sh
View File

@ -1,21 +1,35 @@
# /bin/bash
dockfile=""
tempf() {
case "$(uname -s)" in
Darwin )
local f="$(mktemp)"
mkdir -p $HOME/.tmp
mv "$f" $HOME/.tmp
echo "$HOME/.tmp/${f##*/}"
;;
* )
mktemp "$@"
;;
esac
}
function main() {
set -e
set -u
thispkg="${PWD##*$GOPATH/}"
thisexec="$(basename "$thispkg")"
function cleanup() {
rm "$dockfile"
if [ -z "${DONOTDELETE:-""}" ]; then
echo rm "$dockfile"
fi
}
trap cleanup EXIT
if [ "$(uname -s)" == "Darwin" ]; then
dockfile="$(mktemp -t . tmpXXXX | tail -n 1)"
echo "$dockfile"
else
dockfile="$(mktemp -p . tmpXXXX)"
fi
dockfile="$(tempf)"
echo "$dockfile"
if [ -n "$(ls ./*.go 2>/dev/null )" ]; then
echo "PACKING GO..."
@ -102,6 +116,8 @@ function py3_dockerfiles() {
DOCKERFILE+="${i}"$'\n'
done
echo "$DOCKERFILE" > "$dockfile"
echo $dockfile
cat $dockfile
}
function py2_dockerfiles() {
@ -138,14 +154,18 @@ function py2_dockerfiles() {
DOCKERFILE+="${i}"$'\n'
done
echo "$DOCKERFILE" > "$dockfile"
echo $dockfile
cat $dockfile
}
function go_dockerfiles() {
GOOS=linux CGO_ENABLED=0 go build -o ./exec-$thisexec -a -installsuffix cgo
if ! [ -e "./exec-$thisexec" ]; then
GOOS=linux CGO_ENABLED=0 go build -o ./exec-$thisexec -a -installsuffix cgo
fi
from="golang:1.10-alpine"
if [ "$(uname -s)" == "Darwin" ]; then
from="registry-app.eng.qops.net:5001/imported/alpine/golang:1.10-alpine"
from="golang:1.13-alpine"
if [ "$(uname -s)" == "Darwin" ] && ssh eng hostname; then
from="registry-app.eng.qops.net:5001/imported/alpine:3.12"
fi
#FROM '"$from"' as builder
@ -164,25 +184,30 @@ fi
#========================
DOCKERFILE='
FROM alpine as certs
FROM '"$from"' as certs
RUN apk update && apk add --no-cache ca-certificates
FROM busybox:glibc
COPY . .
RUN mkdir -p /var/log
WORKDIR /main
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
COPY . .
RUN test -e /main/exec-'"$thisexec"'
ENV GOPATH=""
ENV MNT="/mnt/"
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
ENTRYPOINT ["/main/exec-'"$thisexec"'"]
CMD []
'
echo "$DOCKERFILE" > "$dockfile"
echo $dockfile
cat $dockfile
}
function rb_dockerfiles() {
from="ruby:2.6.2-alpine3.9"
from="ruby:2.7.0-alpine3.11"
if [ "$(uname -s)" == "Darwin" ]; then
from="registry-app.eng.qops.net:5001/imported/alpine/ruby:alpine"
fi
@ -193,7 +218,8 @@ gf=""
if [ -e ./Gemfile ]; then
gf='
COPY ./Gemfile /main/Gemfile
RUN BUNDLE_FORCE_RUBY_PLATFORM=1 bundler install --gemfile=/main/Gemfile
RUN bundle config build.google-protobuf --with-cflags=-D__va_copy=va_copy \
&& BUNDLE_FORCE_RUBY_PLATFORM=1 bundler install --gemfile=/main/Gemfile
'
fi
@ -216,14 +242,12 @@ RUN apk add --no-cache ruby ruby-bundler make gcc libc-dev
FROM '"$from"'
MAINTAINER breel@qualtrics.com
RUN rm -rf /usr/local/lib/ruby/2.6.0/rubygems /usr/local/bundle/gems /usr/local/bundle/specifications /usr/local/lib/ruby/gems /usr/local/bundle/extensions
RUN mkdir -p /usr/local/lib/ruby/2.6.0/ /usr/local/bundle/ /usr/local/bundle/ /usr/local/lib/ruby/ /usr/local/bundle/
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
COPY --from=builder /usr/local/lib/ruby/2.6.0/rubygems /usr/local/lib/ruby/2.6.0/rubygems
COPY --from=builder /usr/local/bundle/gems /usr/local/bundle/gems
COPY --from=builder /usr/local/bundle/specifications /usr/local/bundle/specifications
COPY --from=builder /usr/local/lib/ruby/gems /usr/local/lib/ruby/gems
COPY --from=builder /usr/local/bundle/extensions /usr/local/bundle/extensions
RUN rm -rf /usr/local/lib/ruby /usr/local/bundle/
RUN mkdir -p /usr/local/lib/ /usr/local/bundle/
RUN apk update && apk add --no-cache ca-certificates
#COPY --from=certs /etc/ssl/certs /etc/ssl/certs
COPY --from=builder /usr/local/lib/ /usr/local/lib/
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
WORKDIR /main
ENV HOME=/main
ENV MNT=/mnt/
@ -233,6 +257,8 @@ ENTRYPOINT ["ruby", "/main/'"${main##*/}"'"]
CMD []
'
echo "$DOCKERFILE" > "$dockfile"
echo $dockfile
cat $dockfile
}
main $@