entrypoint/: run given command

refs #2
This commit is contained in:
Alexander A. Klimov 2020-06-24 15:04:03 +02:00
parent 682db5f95a
commit 754762bcb7
3 changed files with 66 additions and 0 deletions

View File

@ -1,3 +1,11 @@
FROM golang:buster as entrypoint
COPY entrypoint /entrypoint
WORKDIR /entrypoint
RUN ["go", "build", "."]
FROM debian:buster-slim
RUN ["bash", "-exo", "pipefail", "-c", "export DEBIAN_FRONTEND=noninteractive; apt-get update; apt-get install --no-install-{recommends,suggests} -y locales; apt-get clean; rm -vrf /var/lib/apt/lists/*"]
@ -6,6 +14,8 @@ RUN ["locale-gen", "-j", "4"]
RUN ["bash", "-exo", "pipefail", "-c", "export DEBIAN_FRONTEND=noninteractive; apt-get update; apt-get install --no-install-{recommends,suggests} -y apache2 libapache2-mod-php7.3 php-{imagick,redis} php7.3-{bcmath,bz2,common,curl,dba,enchant,gd,gmp,imap,interbase,intl,json,ldap,mbstring,mysql,odbc,opcache,pgsql,pspell,readline,recode,snmp,soap,sqlite3,sybase,tidy,xml,xmlrpc,xsl,zip}; apt-get clean; rm -vrf /var/lib/apt/lists/*"]
COPY --from=entrypoint /entrypoint/entrypoint /entrypoint
RUN ["a2enmod", "rewrite"]
RUN ["ln", "-vsf", "/dev/stdout", "/var/log/apache2/access.log"]
RUN ["ln", "-vsf", "/dev/stderr", "/var/log/apache2/error.log"]
@ -18,3 +28,5 @@ EXPOSE 8080
RUN ["chmod", "o+x", "/var/log/apache2"]
RUN ["chown", "www-data:www-data", "/var/run/apache2"]
RUN ["install", "-o", "www-data", "-g", "www-data", "-d", "/etc/icingaweb2"]
ENTRYPOINT ["/entrypoint"]

3
entrypoint/go.mod Normal file
View File

@ -0,0 +1,3 @@
module entrypoint
go 1.14

51
entrypoint/main.go Normal file
View File

@ -0,0 +1,51 @@
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"path/filepath"
"syscall"
"time"
)
func main() {
if err := entrypoint(); err != nil {
logf("crit", "%s", err.Error())
os.Exit(1)
}
}
func entrypoint() error {
if len(os.Args) < 2 {
logf("warn", "Nothing to do.")
return nil
}
path := os.Args[1]
if filepath.Base(path) == path {
logf("info", "Looking up %#v in $PATH", path)
abs, errLP := exec.LookPath(path)
if errLP != nil {
return errLP
}
path = abs
}
logf("info", "Running %#v", path)
return syscall.Exec(path, os.Args[1:], os.Environ())
}
var out = bufio.NewWriter(os.Stderr)
func logf(severity, format string, a ...interface{}) {
_, _ = fmt.Fprintf(out, "[%s] ", time.Now().Format("Mon Jan 2 15:04:05.999999999 2006"))
_, _ = fmt.Fprintf(out, "[docker_entrypoint:%s] [pid %d] DOCKERE: ", severity, os.Getpid())
_, _ = fmt.Fprintf(out, format, a...)
_, _ = fmt.Fprintln(out)
_ = out.Flush()
}