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