-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated base image and some more functionality
1. Rebased the image on the centos:8 image 2. Removed all env-var handling code as its basically superseded by the systemd `PassEnvironment` option that can be specified on a per-unit-file basis 3. Made systemd and journald output go to `/dev/console` which should be collected by the container engine automatically 4. Made a new service unit file that tries to run the arguments given to the container as commands after all systemd services have started and exit the container once those commands are done while returning an appropriate return value. 5. It is possible to have environment variables passed to the invoked commands by setting variable names in the `ARGS_ENV_INCLUDE` variable either when launching the container or when building derived containers Note: The CentOs version upgrade is required, among other things, because the `systemd` version in CentOS 7 does not support returning exit codes on exit. Note: Certain versions of Docker have an issue with collecting `/dev/console` properly. See the following for explanation: - systemd/systemd#4262 - moby/moby#27202 - https://bugzilla.redhat.com/show_bug.cgi?id=1373780 This image also include a workaround for the following Podman issue: - containers/podman#4625 Signed-off-by: Barak Korren <[email protected]>
- Loading branch information
Showing
9 changed files
with
116 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# This file is part of systemd. | ||
# | ||
# systemd is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Lesser General Public License as published by | ||
# the Free Software Foundation; either version 2.1 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Entries in this file show the compile time defaults. | ||
# You can change settings by editing this file. | ||
# Defaults can be restored by simply deleting this file. | ||
# | ||
# See journald.conf(5) for details. | ||
|
||
[Journal] | ||
#Storage=auto | ||
#Compress=yes | ||
#Seal=yes | ||
#SplitMode=uid | ||
#SyncIntervalSec=5m | ||
#RateLimitIntervalSec=30s | ||
#RateLimitBurst=10000 | ||
#SystemMaxUse= | ||
#SystemKeepFree= | ||
#SystemMaxFileSize= | ||
#SystemMaxFiles=100 | ||
#RuntimeMaxUse= | ||
#RuntimeKeepFree= | ||
#RuntimeMaxFileSize= | ||
#RuntimeMaxFiles=100 | ||
#MaxRetentionSec= | ||
#MaxFileSec=1month | ||
#ForwardToSyslog=no | ||
#ForwardToKMsg=no | ||
ForwardToConsole=yes | ||
#ForwardToWall=yes | ||
TTYPath=/dev/console | ||
#MaxLevelStore=debug | ||
#MaxLevelSyslog=debug | ||
#MaxLevelKMsg=notice | ||
MaxLevelConsole=debug | ||
#MaxLevelWall=emerg | ||
#LineMax=48K |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[Unit] | ||
Description=Run container command | ||
|
||
[Service] | ||
Type=oneshot | ||
PassEnvironment=ARGS_EXPORT_PATH $ARGS_ENV_INCLUDE | ||
# Remove this service file so that if the container layer is committed, the | ||
# resulting image will not contain the given command information | ||
ExecStartPre=-/usr/bin/systemctl disable --no-reload run-args.service | ||
ExecStartPre=-/usr/bin/rm -f /etc/systemd/system/run-args.service | ||
ExecStart=/sbin/run_args.sh ${ARGS_EXPORT_PATH} | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash -e | ||
# Read command-line arguments and store them in a file to be used later | ||
# | ||
if [[ $# -gt 0 ]] && [[ $1 ]]; then | ||
# Podman seems to have an issue where `podman commit` cannot create images | ||
# without a CMD setting, and adding `--change='CMD []'` results in the | ||
# command being an array with a single string in it. Therefor we detect that | ||
# particular case above and treat it as if a command was not given | ||
echo "Got $# command-line arguments, enabling run-args service" | ||
printf '%s\n' "$@" > "$ARGS_EXPORT_PATH" | ||
# Update list of variables that systemd will pass to invoked process on the | ||
# fly. Unfortunately this dirty `sed` is the only way to do that | ||
# | ||
# We create the *.service file from in *.service.in file rather then making | ||
# the change to the file in-place, so that the change can be undone without | ||
# leaving overlayfs records behind | ||
# | ||
/usr/bin/sed -re "s/\\\$ARGS_ENV_INCLUDE/$ARGS_ENV_INCLUDE/" \ | ||
/etc/systemd/system/run-args.service.in \ | ||
> /etc/systemd/system/run-args.service \ | ||
# Enable service to run the arguments | ||
systemctl enable run-args.service | ||
fi | ||
|
||
exec /usr/sbin/init |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# run_args.sh - Run command from a given file | ||
# | ||
( | ||
# Run in a subshell so -e only applies to the commands in parantheses | ||
set -e | ||
CMD_FILE="${1:?Args file not passed to run_args.sh}" | ||
if ! [[ -r "$CMD_FILE" ]]; then | ||
echo "run_args.sh: Args file: '$CMD_FILE' not found" | ||
fi | ||
mapfile -t CMD < "$CMD_FILE" | ||
# remove the file since we don't need it anymore | ||
rm -f "$CMD_FILE" || : | ||
# Finally run the command | ||
"${CMD[@]}" | ||
) | ||
# Since this script is not running with -e the command below will always run | ||
systemctl exit $? | ||
# Exit with 0 so systemd doesn't think the service had failed | ||
exit 0 |
This file was deleted.
Oops, something went wrong.