mirror of
https://github.com/containers/podman.git
synced 2025-07-04 10:10:32 +08:00
Add nohosts option to /build and /libpod/build
Signed-off-by: Gavin Lam <gavin.oss@tutamail.com>
This commit is contained in:
@ -142,6 +142,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
|
||||
Memory int64 `schema:"memory"`
|
||||
NamespaceOptions string `schema:"nsoptions"`
|
||||
NoCache bool `schema:"nocache"`
|
||||
NoHosts bool `schema:"nohosts"`
|
||||
OmitHistory bool `schema:"omithistory"`
|
||||
OSFeatures []string `schema:"osfeature"`
|
||||
OSVersion string `schema:"osversion"`
|
||||
@ -720,6 +721,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
|
||||
LabelOpts: labelOpts,
|
||||
Memory: query.Memory,
|
||||
MemorySwap: query.MemSwap,
|
||||
NoHosts: query.NoHosts,
|
||||
OmitHistory: query.OmitHistory,
|
||||
SeccompProfilePath: seccomp,
|
||||
ShmSize: strconv.Itoa(query.ShmSize),
|
||||
|
@ -523,6 +523,12 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
|
||||
// TBD Extra hosts to add to /etc/hosts
|
||||
// (As of version 1.xx)
|
||||
// - in: query
|
||||
// name: nohosts
|
||||
// type: boolean
|
||||
// default:
|
||||
// description: |
|
||||
// Not to create /etc/hosts when building the image
|
||||
// - in: query
|
||||
// name: remote
|
||||
// type: string
|
||||
// default:
|
||||
@ -1502,6 +1508,12 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
|
||||
// TBD Extra hosts to add to /etc/hosts
|
||||
// (As of version 1.xx)
|
||||
// - in: query
|
||||
// name: nohosts
|
||||
// type: boolean
|
||||
// default:
|
||||
// description: |
|
||||
// Not to create /etc/hosts when building the image
|
||||
// - in: query
|
||||
// name: remote
|
||||
// type: string
|
||||
// default:
|
||||
|
@ -335,6 +335,9 @@ func Build(ctx context.Context, containerFiles []string, options types.BuildOpti
|
||||
if options.NoCache {
|
||||
params.Set("nocache", "1")
|
||||
}
|
||||
if options.CommonBuildOpts.NoHosts {
|
||||
params.Set("nohosts", "1")
|
||||
}
|
||||
if t := options.Output; len(t) > 0 {
|
||||
params.Set("output", t)
|
||||
}
|
||||
|
@ -737,6 +737,31 @@ RUN [[ -L /test/dummy-symlink ]] && echo SYMLNKOK || echo SYMLNKERR`, CITEST_IMA
|
||||
Expect(session.OutputToString()).To(ContainSubstring("SYMLNKOK"))
|
||||
})
|
||||
|
||||
It("podman build --no-hosts", func() {
|
||||
targetPath := podmanTest.TempDir
|
||||
|
||||
containerFile := filepath.Join(targetPath, "Containerfile")
|
||||
content := `FROM scratch
|
||||
RUN echo '56.78.12.34 image.example.com' > /etc/hosts`
|
||||
|
||||
Expect(os.WriteFile(containerFile, []byte(content), 0755)).To(Succeed())
|
||||
|
||||
defer func() {
|
||||
Expect(os.RemoveAll(containerFile)).To(Succeed())
|
||||
}()
|
||||
|
||||
session := podmanTest.Podman([]string{
|
||||
"build", "--pull-never", "-t", "hosts_test", "--no-hosts", "--from", CITEST_IMAGE, targetPath,
|
||||
})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
|
||||
session = podmanTest.Podman([]string{"run", "--no-hosts", "--rm", "hosts_test", "cat", "/etc/hosts"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(session.OutputToString()).To(Equal("56.78.12.34 image.example.com"))
|
||||
})
|
||||
|
||||
It("podman build --from, --add-host, --cap-drop, --cap-add", func() {
|
||||
targetPath := podmanTest.TempDir
|
||||
|
||||
|
Reference in New Issue
Block a user