Compare commits

..

10 Commits

Author SHA1 Message Date
Bel LaPointe
41c9625598 k 2023-04-10 11:03:25 -06:00
bel
c8f015930e Build go without a container to avoid vendor 2019-06-22 16:27:34 -06:00
Bel LaPointe
429bc20133 no more logger 2019-05-02 09:35:43 -06:00
Bel LaPointe
a52a087202 ruby smaller 2019-04-15 14:04:41 -06:00
Bel LaPointe
114cbdd461 ruby fix 2019-04-15 13:37:41 -06:00
Bel LaPointe
a98e30ee96 we now have ruby 2019-04-10 14:23:21 -06:00
Bel LaPointe
3da2eece62 inline compile script 2019-01-14 09:41:34 -07:00
Bel LaPointe
94b257ad4d hopefully 2018-11-11 09:27:49 -07:00
Bel LaPointe
94737c4807 whoops 2018-10-13 19:23:10 -06:00
Bel LaPointe
477b3be32c .gitfiles 2018-10-06 21:58:24 -06:00
5 changed files with 319 additions and 43 deletions

3
.gitattributes vendored Executable file
View File

@@ -0,0 +1,3 @@
vendor/**/* -diff
vendor/vendor.json diff
testdata/* -diff

10
.gitignore vendored Executable file
View File

@@ -0,0 +1,10 @@
*.key
*.crt
*.pem
*.swp
*.swo
*.pub
cli-keys
fake-ssh
gcpkeys
*.json

4
build_go_exec Executable file
View File

@@ -0,0 +1,4 @@
#! /bin/bash
o="${1:-$(mktemp /tmp/execXXX)}"
GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -o "$o" -a -installsuffix cgo
echo "$o"

166
do.sh
View File

@@ -1,28 +1,43 @@
# /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")"
function cleanup() { function cleanup() {
rm "$compile" if [ -z "${DONOTDELETE:-""}" ]; then
rm "$dockfile" echo rm "$dockfile"
fi
} }
trap cleanup EXIT trap cleanup EXIT
if [ "$(uname -s)" == "Darwin" ]; then dockfile="$(tempf)"
compile="$(mktemp -t . tmpXXXXX | tail -n 1)" echo "$dockfile"
dockfile="$(mktemp -t . tmpXXXX | tail -n 1)"
echo ,"$compile", ."$dockfile".
else
compile="$(mktemp -p . tmpXXXXX)"
dockfile="$(mktemp -p . tmpXXXX)"
fi
if [ "$(ls ./*.go 2>/dev/null )" != "" ]; then if [ -n "$(ls ./*.go 2>/dev/null )" ]; then
echo "PACKING GO..." echo "PACKING GO..."
go_dockerfiles go_dockerfiles
elif [ "$(ls ./*.py 2>/dev/null )" != "" ]; then elif [ -n "$(ls ./*.rb 2> /dev/null)" ]; then
echo "PACKING RUBY..."
rb_dockerfiles
elif [ -n "$(ls ./*.py 2>/dev/null )" ]; then
if [ "$(ls ./main.py 2>/dev/null )" != "" ] && [[ "$(head -n 1 ./main.py)" == *python2* ]]; then if [ "$(ls ./main.py 2>/dev/null )" != "" ] && [[ "$(head -n 1 ./main.py)" == *python2* ]]; then
echo "PACKING PYTHON2..." echo "PACKING PYTHON2..."
py2_dockerfiles py2_dockerfiles
@@ -67,7 +82,7 @@ function py3_dockerfiles() {
f=() f=()
f+=('') f+=('')
f+=('FROM alpine as certs') f+=('FROM alpine as certs')
f+=('RUN apk update && apk add ca-certificates') f+=('RUN apk update && apk add --no-cache ca-certificates')
f+=('') f+=('')
f+=('#========================') f+=('#========================')
f+=('') f+=('')
@@ -101,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() {
@@ -117,68 +134,131 @@ function py2_dockerfiles() {
from="${from}" from="${from}"
fi fi
echo "$DOCKERFILE" > "$dockfile"
f=() f=()
f+=('') f+=('')
f+=('FROM alpine as certs') f+=('FROM alpine as certs')
f+=('RUN apk update && apk add ca-certificates') f+=('RUN apk update && apk add --no-cache ca-certificates')
f+=('') f+=('')
f+=('#========================') f+=('#========================')
f+=('') f+=('')
f+=('FROM '"${from}"'') f+=('FROM '"${from}"'')
f+=('WORKDIR /main/') f+=('WORKDIR /main/')
f+=('COPY --from=certs /etc/ssl/certs /etc/ssl/certs') f+=('COPY --from=certs /etc/ssl/certs /etc/ssl/certs')
f+=('COPY . .')
f+=('COPY ./'"$(basename ${reqFile})"' /main/req.txt') f+=('COPY ./'"$(basename ${reqFile})"' /main/req.txt')
f+=('RUN pip2.7 install -r /main/req.txt') f+=('RUN pip2.7 install -r /main/req.txt')
f+=('COPY . .')
f+=('ENTRYPOINT ["python2.7", "/main/main.py"]') f+=('ENTRYPOINT ["python2.7", "/main/main.py"]')
f+=('') f+=('')
DOCKERFILE="" DOCKERFILE=""
for i in "${f[@]}"; do for i in "${f[@]}"; do
DOCKERFILE+="${i}"$'\n' DOCKERFILE+="${i}"$'\n'
done done
echo "$DOCKERFILE" > "$dockfile"
echo $dockfile
cat $dockfile
} }
function go_dockerfiles() { function go_dockerfiles() {
echo ' if ! [ -e "./exec-$thisexec" ]; then
#! /bin/sh GOOS=linux CGO_ENABLED=0 go build -o ./exec-$thisexec -a -installsuffix cgo
fi
set -e from="golang:1.13-alpine"
set -u if [ "$(uname -s)" == "Darwin" ] && ssh eng hostname; then
from="registry-app.eng.qops.net:5001/imported/alpine:3.12"
CGO_ENABLED=0 go build -o /go/bin/exec -a -installsuffix cgo
' > "$compile"
from="golang:1.10-alpine"
if [ "$(uname -s)" == "Darwin" ]; then
from="registry-app.eng.qops.net:5001/imported/alpine/golang:1.10-alpine"
fi fi
DOCKERFILE=' #FROM '"$from"' as builder
FROM '"$from"' as builder #MAINTAINER breel@qualtrics.com
MAINTAINER breel@qualtrics.com #
#RUN apk add --no-cache git
WORKDIR /go/'"$thispkg"' #
COPY . . #WORKDIR /go/'"$thispkg"'
RUN /bin/sh '"$compile"' #COPY . .
#RUN /bin/sh -c "CGO_ENABLED=0 go build -o /go/bin/'"$thisexec"' -a -installsuffix cgo"
FROM alpine as certs #
RUN apk update && apk add ca-certificates #FROM busybox:glibc
#COPY --from=builder /go/'"$thispkg"' /main
#COPY --from=builder /go/bin /main
#======================== #========================
DOCKERFILE='
FROM '"$from"' as certs
RUN apk update && apk add --no-cache ca-certificates
FROM busybox:glibc FROM busybox:glibc
COPY --from=builder /go/bin /main
COPY --from=builder /go/'"$thispkg"' /main
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 /etc/ssl/certs /etc/ssl ENTRYPOINT ["/main/exec-'"$thisexec"'"]
COPY --from=certs /etc/ssl/certs /etc/ssl/certs CMD []
ENTRYPOINT ["/main/exec"]
' '
echo "$DOCKERFILE" > "$dockfile" echo "$DOCKERFILE" > "$dockfile"
echo $dockfile
cat $dockfile
} }
main function rb_dockerfiles() {
from="ruby:2.7.0-alpine3.11"
if [ "$(uname -s)" == "Darwin" ]; then
from="registry-app.eng.qops.net:5001/imported/alpine/ruby:alpine"
fi
cp=( $(find . -mindepth 1 -maxdepth 1 -type f | grep -v "$dockfile" | grep -v '\.[^\.]*\.sw[a-z]$' | grep -v '\.tar$' ) )
cpd=( $(find . -mindepth 1 -maxdepth 1 -type d | grep -v \\.git || true) )
gf=""
if [ -e ./Gemfile ]; then
gf='
COPY ./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
main="$(find . -maxdepth 1 -name main.rb || find . -maxdepth 1 -name "*.rb" | head -n 1)"
DOCKERFILE='
FROM alpine as certs
RUN apk update && apk add --no-cache ca-certificates
#========================
FROM '"$from"' as builder
RUN mkdir -p /var/log
RUN apk add --no-cache ruby ruby-bundler make gcc libc-dev
'"$gf"'
#CMD []
#ENTRYPOINT ["sh"]
#========================
FROM '"$from"'
MAINTAINER breel@qualtrics.com
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/
COPY '"${cp[@]}"' /main/
'"$(for dir in ${cpd[@]}; do printf "COPY $dir /main/${dir##*/}\n"; done)"'
ENTRYPOINT ["ruby", "/main/'"${main##*/}"'"]
CMD []
'
echo "$DOCKERFILE" > "$dockfile"
echo $dockfile
cat $dockfile
}
main $@

179
gitea.sh Executable file
View File

@@ -0,0 +1,179 @@
# /bin/bash
function main() {
set -e
set -u
thispkg="${PWD##*$GOPATH/}"
thisexec="$(basename "$thispkg")"
function cleanup() {
rm "$dockfile"
}
trap cleanup EXIT
if [ "$(uname -s)" == "Darwin" ]; then
dockfile="$(mktemp -t . tmpXXXX | tail -n 1)"
echo "$dockfile"
else
dockfile="$(mktemp -p . tmpXXXX)"
fi
if [ "$(ls ./*.go 2>/dev/null )" != "" ]; then
echo "PACKING GO..."
go_dockerfiles
elif [ "$(ls ./*.py 2>/dev/null )" != "" ]; then
if [ "$(ls ./main.py 2>/dev/null )" != "" ] && [[ "$(head -n 1 ./main.py)" == *python2* ]]; then
echo "PACKING PYTHON2..."
py2_dockerfiles
else
echo "PACKING PYTHON3..."
py3_dockerfiles
fi
fi
if [ "$#" -lt 1 ]; then
args="-t ${thispkg##*/}:latest"
else
args="$*"
fi
docker build $args -f "$dockfile" .
}
function py3_dockerfiles() {
echo "PY3"
img="${1:-python}"
if [[ "$(ls ./*req*.txt 2>/dev/null)" == "" ]]; then
echo "NEED requirements.txt"
exit 1
fi
reqFile="$(ls ./*req*.txt | head -n 1)"
if [[ "$img" == "python" ]]; then
from="python:3.7.0-alpine3.8"
elif [[ "$img" == "pypy" ]]; then
from="pypy:3-6.0.0-slim-jessie"
else
echo "ERR py3_dockerfile can be '', 'python', or 'pypy', not ${img}"
fi
if [ "$(uname -s)" == "Darwin" ]; then
from="${from}"
fi
f=()
f+=('')
f+=('FROM alpine as certs')
f+=('RUN apk update && apk add ca-certificates')
f+=('')
f+=('#========================')
f+=('')
f+=('FROM '"${from}"'')
f+=('WORKDIR /main/')
f+=('COPY --from=certs /etc/ssl/certs /etc/ssl/certs')
f+=('')
if [[ "$img" == "python" ]]; then
echo ""
#f+=('RUN apk add linux-headers')
#f+=('RUN apk add g++ gcc make')
else
echo ""
#f+=('RUN apt-get update')
#f+=('RUN apt-get install -y linux-headers')
#f+=('RUN apt-get install -y g++ gcc make')
fi
f+=('')
f+=('COPY ./'"$(basename ${reqFile})"' /main/req.txt')
f+=('RUN pip install -r /main/req.txt')
f+=('')
f+=('COPY . .')
if [[ "$img" == "python" ]]; then
f+=('ENTRYPOINT ["python3", "/main/main.py"]')
else
f+=('ENTRYPOINT ["pypy3", "/main/main.py"]')
fi
f+=('')
DOCKERFILE=""
for i in "${f[@]}"; do
DOCKERFILE+="${i}"$'\n'
done
echo "$DOCKERFILE" > "$dockfile"
}
function py2_dockerfiles() {
echo "PY2"
if [[ "$(ls ./*req*.txt 2>/dev/null)" == "" ]]; then
echo "NEED requirements.txt"
exit 1
fi
reqFile="$(ls ./*req*.txt | head -n 1)"
from="python:2.7.15-alpine3.8"
if [ "$(uname -s)" == "Darwin" ]; then
from="${from}"
fi
echo "$DOCKERFILE" > "$dockfile"
f=()
f+=('')
f+=('FROM alpine as certs')
f+=('RUN apk update && apk add ca-certificates')
f+=('')
f+=('#========================')
f+=('')
f+=('FROM '"${from}"'')
f+=('WORKDIR /main/')
f+=('COPY --from=certs /etc/ssl/certs /etc/ssl/certs')
f+=('COPY . .')
f+=('COPY ./'"$(basename ${reqFile})"' /main/req.txt')
f+=('RUN pip2.7 install -r /main/req.txt')
f+=('ENTRYPOINT ["python2.7", "/main/main.py"]')
f+=('')
DOCKERFILE=""
for i in "${f[@]}"; do
DOCKERFILE+="${i}"$'\n'
done
}
function go_dockerfiles() {
from="golang:1.10-alpine"
if [ "$(uname -s)" == "Darwin" ]; then
from="registry-app.eng.qops.net:5001/imported/alpine/golang:1.10-alpine"
fi
DOCKERFILE='
FROM '"$from"' as builder
MAINTAINER breel@qualtrics.com
RUN apk add --no-cache git
WORKDIR /go/'"$thispkg"'
COPY . .
RUN /bin/sh -c "CGO_ENABLED=0 go build -o /go/bin/'"$thisexec"' -a -installsuffix cgo -tags bindata -ldflags '"' -s -w -X \"main.Version=dev\" -X \"main.Tags=bindata\"'"'"
FROM alpine as certs
RUN apk update && apk add ca-certificates
#========================
FROM '"$from"'
RUN apk add --no-cache git
COPY --from=builder /go/'"$thispkg"' /main
COPY --from=builder /go/bin /main
RUN rm -rf /main/vendor /main/modules
RUN mkdir -p /var/log
WORKDIR /main
ENV GOPATH=""
ENV MNT="/mnt/"
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
ENTRYPOINT ["/main/'"$thisexec"'"]
CMD []
'
echo "$DOCKERFILE" > "$dockfile"
}
main $@