Compare commits
6 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edd4dcf23d |
||
|
|
5943f8b0df | ||
|
|
bb4de6e898 | ||
|
|
b76966c1da | ||
|
|
0e46089967 | ||
|
|
737e6b7934 |
24 changed files with 978 additions and 1154 deletions
1
5
Symbolic link
1
5
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
.
|
||||
71
Dockerfile
71
Dockerfile
|
|
@ -1,38 +1,47 @@
|
|||
FROM registry.fedoraproject.org/fedora:28
|
||||
ENV NAME=varnish \
|
||||
VARNISH_VERSION=5.0.0 \
|
||||
FROM registry.fedoraproject.org/f28/s2i-core:latest
|
||||
|
||||
EXPOSE 8080
|
||||
EXPOSE 8443
|
||||
|
||||
ENV SUMMARY="Platform for running Varnish or building Varnish-based application" \
|
||||
DESCRIPTION="Varnish available as container is a base platform for \
|
||||
running Varnish server or building Varnish-based application. \
|
||||
Varnish Cache stores web pages in memory so web servers don't have to create \
|
||||
the same web page over and over again. Varnish Cache serves pages much faster \
|
||||
than any application server; giving the website a significant speed up." \
|
||||
VERSION=0 \
|
||||
RELEASE=1 \
|
||||
ARCH=x86_64
|
||||
VARNISH_CONFIGURATION_PATH=/etc/varnish
|
||||
|
||||
# Labels
|
||||
LABEL com.redhat.component="$NAME" \
|
||||
name="$FGC/$NAME" \
|
||||
summary="Varnish is an HTTP accelerator" \
|
||||
description="Varnish is an HTTP accelerator designed for content-heavy dynamic web sites." \
|
||||
version="$VERSION" \
|
||||
release="$RELEASE.$DISTTAG" \
|
||||
architecture="$ARCH" \
|
||||
usage="docker run -p <PORT>:6081 -p <MANAGEMENT_PORT>:6082" \
|
||||
io.k8s.description="Varnish is an HTTP accelerator designed for content-heavy dynamic web sites." \
|
||||
io.k8s.display-name="Varnish" \
|
||||
io.openshift.expose-services="6801:http,6802:http" \
|
||||
io.openshift.tags="http,proxy,varnish,varnish5"
|
||||
LABEL summary="$SUMMARY" \
|
||||
description="$DESCRIPTION" \
|
||||
io.k8s.description="$DESCRIPTION" \
|
||||
io.k8s.display-name="Varnish 5" \
|
||||
io.openshift.expose-services="8080:http,8443:https" \
|
||||
io.openshift.tags="builder,varnish" \
|
||||
version="$VERSION" \
|
||||
com.redhat.component="varnish" \
|
||||
usage="s2i build https://github.com/sclorg/varnish-container.git --context-dir=5/test/test-app/ $FGC/varnish sample-server" \
|
||||
name="$FGC/varnish" \
|
||||
maintainer="SoftwareCollections.org <sclorg@redhat.com>"
|
||||
|
||||
# Install varnish
|
||||
RUN dnf install -y --nogpgcheck varnish && \
|
||||
dnf clean all && \
|
||||
mkdir /varnish_secret && mkdir /varnish_config && \
|
||||
dd if=/dev/random of=/varnish_secret/varnish_secret count=1
|
||||
RUN INSTALL_PKGS="gettext hostname nss_wrapper bind-utils varnish" && \
|
||||
dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
|
||||
rpm -V $INSTALL_PKGS && \
|
||||
fix-permissions $VARNISH_CONFIGURATION_PATH && \
|
||||
fix-permissions /var/lib/varnish && \
|
||||
rm -f /etc/profile.d/lang.sh && \
|
||||
rm -f /etc/profile.d/lang.csh && \
|
||||
dnf -y clean all --enablerepo='*'
|
||||
|
||||
# Add configuration file
|
||||
COPY files/default.vcl /varnish_config/default.vcl
|
||||
# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH
|
||||
COPY 5/s2i/bin/ $STI_SCRIPTS_PATH
|
||||
|
||||
# Copy help file
|
||||
COPY root/help.1 /
|
||||
# Copy extra files to the image.
|
||||
COPY 5/root/ /
|
||||
|
||||
# Expose ports for varnish and it's admin CLI
|
||||
EXPOSE 6801 6802
|
||||
# Reset permissions of filesystem to default values
|
||||
RUN rpm-file-permissions
|
||||
|
||||
# Generate a new secret and start varnish in the foreground
|
||||
CMD /usr/sbin/varnishd -f /varnish_config/default.vcl -a :6081 -T :6082 -s malloc,256M -S /varnish_secret/varnish_secret -F
|
||||
USER 1001
|
||||
|
||||
CMD $STI_SCRIPTS_PATH/usage
|
||||
|
|
|
|||
1
Dockerfile.fedora
Symbolic link
1
Dockerfile.fedora
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
Dockerfile
|
||||
674
LICENSE
674
LICENSE
|
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
31
Makefile
31
Makefile
|
|
@ -1,31 +0,0 @@
|
|||
.PHONY: build run default
|
||||
|
||||
# Docker container tag
|
||||
IMAGE_NAME = modularitycontainers/varnish
|
||||
|
||||
# Port varnish will serve content on
|
||||
PORT = 8080
|
||||
|
||||
# Port you can later access with varnish admin CLI
|
||||
MANAGEMENT_PORT = 6082
|
||||
|
||||
# Here you can link your other containers to be used as backend servers
|
||||
# as container_name:hostname
|
||||
# please note that you have to add the hostname in the configuration too
|
||||
LINK =
|
||||
|
||||
# Addtional flags for Docker
|
||||
FLAGS =
|
||||
|
||||
# Modulemd file
|
||||
MODULEMDURL = http://pkgs.fedoraproject.org/cgit/modules/varnish.git/plain/varnish.yaml
|
||||
|
||||
default: run
|
||||
|
||||
build:
|
||||
docker build --tag=$(IMAGE_NAME) .
|
||||
|
||||
run: build
|
||||
docker run $(FLAGS) -p $(PORT):6081 -p $(MANAGEMENT_PORT):6082 $(foreach link,$(LINK), --link $(link) ) $(IMAGE_NAME)
|
||||
test:
|
||||
cd tests; CONFIG=config.yaml MODULE=docker MODULEMD=$(MODULEMDURL) URL="docker=$(IMAGE_NAME)" make test1
|
||||
150
README.md
150
README.md
|
|
@ -1,104 +1,78 @@
|
|||
# Varnish HTTP Cache container
|
||||
Varnish Cache 5.0 HTTP reverse proxy Container image
|
||||
=====================================================
|
||||
|
||||
This repository contains resources for Varnish cache container. This is an example, so it is not recommended to use it in production, but feel free to try it out. It uses Fedora 26 Boltron as a base image with Varnish installed as a module.
|
||||
This container image includes Varnish 5.0 Cache server and a reverse proxy for OpenShift and general usage.
|
||||
Users can choose between RHEL and CentOS based images.
|
||||
The RHEL image is available in the [Red Hat Container Catalog](https://access.redhat.com/containers/#/registry.access.redhat.com/rhscl/varnish-5-rhel7)
|
||||
as registry.access.redhat.com/rhscl/varnish-5-rhel7.
|
||||
The CentOS image is then available on [Docker Hub](https://hub.docker.com/r/centos/varnish-5-centos7/)
|
||||
as centos/varnish-5-centos7.
|
||||
|
||||
# Configuration
|
||||
|
||||
You can find the configuration file default.vcl in **files** folder. Varnish secret file is generated each time the container is built, for better security. While this provides *some* security, we strongly advise you always use your own secret (see below in [Running in Docker](#Running-in-Docker)) or do not expose `<MANAGEMENT_PORT>` if you don't need it.
|
||||
Description
|
||||
-----------
|
||||
|
||||
## Backend servers
|
||||
Varnish available as container is a base platform for
|
||||
running Varnish server or building Varnish-based application.
|
||||
Varnish Cache stores web pages in memory so web servers don't have to create
|
||||
the same web page over and over again. Varnish Cache serves pages much faster
|
||||
than any application server, giving the website a significant speed up.
|
||||
|
||||
You can configure servers that are not running on localhost as you would usually, but if you have some servers running locally, there's a little extra work you need to do. I.e. I have container with web server running on port 80 in container and exposed as port 8036 on host. If I wanted to add this container as a backend server, first step would be to get it's name from `docker ps`.
|
||||
The image can be used as a base image for other applications based on Varnish Cache 5.0 or using s2i tool.
|
||||
|
||||
```Shell
|
||||
$ docker ps
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
c756b751d06d nginx "/bin/sh -c nginx" 4 minutes ago Up 4 minutes 0.0.0.0:8036->80/tcp stupefied_albattani
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
To build a simple [sample-app](https://github.com/sclorg/varnish-container/tree/generated/5/test/test-app) application
|
||||
using standalone [S2I](https://github.com/openshift/source-to-image) and then run the
|
||||
resulting image with [Docker](http://docker.io) execute:
|
||||
|
||||
* **For RHEL based image**
|
||||
```
|
||||
$ docker pull registry.access.redhat.com/rhscl/varnish-5-rhel7
|
||||
$ s2i build https://github.com/sclorg/varnish-container.git --context-dir=5/test/test-app/ registry.access.redhat.com/rhscl/varnish-5-rhel7 sample-server
|
||||
$ docker run -p 8080:8080 sample-server
|
||||
```
|
||||
|
||||
* **For CentOS based image**
|
||||
```
|
||||
$ docker pull centos/varnish-5-centos7
|
||||
$ s2i build https://github.com/sclorg/varnish-container.git --context-dir=5/test/test-app/ centos/varnish-5-centos7 sample-server
|
||||
$ docker run -p 8080:8080 sample-server
|
||||
```
|
||||
|
||||
**Accessing the application:**
|
||||
```
|
||||
$ curl 127.0.0.1:8080
|
||||
```
|
||||
|
||||
Next step is to edit the varnish configuration with a hostname of your choice. Let's say I want to call this server back1. Then the configuration would look like this:
|
||||
|
||||
```VCL
|
||||
backend back1 {
|
||||
.host = "back1";
|
||||
.port = "80";
|
||||
}
|
||||
```
|
||||
Note that the port needs to be the one in the container, not in the host. Last step is to link the container itself to your Varnish container. When running the Varnish container, add parameter `--link container_name:hostname` for each backend server running in container from localhost. For my example container I would run it like this:
|
||||
|
||||
```Shell
|
||||
$ docker run -p 6081:6081 -p 6082:6082 --link stupefied_albattani:back1 -v <CONFIG_DIR>:/varnish_config/
|
||||
|
||||
```
|
||||
You might have noticed some ports are published and some volume is mounted, which will be explained in the next section.
|
||||
|
||||
# Running in Docker
|
||||
There are two ways you can run this container in Docker.
|
||||
|
||||
1\) **From shell**
|
||||
|
||||
```Shell
|
||||
docker run -p <PORT>:6081
|
||||
```
|
||||
This is the basic execution of the container. `<PORT>` is the cache frontend on which it will serve content. Varnish has it's own admin CLI (see `<MANAGEMENT_PORT>` below). To access it, you'll need the varnish secret file. Varnish admin CLI is documented [here](https://varnish-cache.org/docs/4.1/reference/varnishadm.html). You can mount your secret file, that has to be named varnish_secret like this:
|
||||
|
||||
```Shell
|
||||
docker run -p <PORT>:6081 -p <MANAGEMENT_PORT>:6082 -v <SECRET_DIR>:/varnish_secret/
|
||||
```
|
||||
|
||||
If you want to use your configuration instead of the default one, name it default.vcl and mount it like this:
|
||||
Configuration
|
||||
-------------
|
||||
No further configuration is required.
|
||||
|
||||
|
||||
```
|
||||
docker run -p $PORT:6081 -v <CONFIG_DIR>:/varnish_config/
|
||||
```
|
||||
S2I build support
|
||||
-------------
|
||||
The Varnish Cache 5.0 Container image supports the S2I tool (see Usage section).
|
||||
Note that the default.vcl configuration file in the directory accessed by S2I needs
|
||||
to be in the VCL format.
|
||||
|
||||
Where `<CONFIG_DIR>` is a directory that contains default.vcl file.
|
||||
Environment variables and volumes
|
||||
-------------
|
||||
No special environment variables or volumes available.
|
||||
|
||||
If mounting gives you an error, it might be due to SELinux, you can then apply following:
|
||||
Troubleshooting
|
||||
---------------
|
||||
Varnish logs into standard output, so the log is available in the container log. The log can be examined by running:
|
||||
|
||||
```
|
||||
chcon -Rt svirt_sandbox_file_t <DIR>
|
||||
```
|
||||
docker logs <container>
|
||||
|
||||
You can also link containers to be used as backend servers, as described in previous section.
|
||||
|
||||
2\) **With a Makefile**
|
||||
|
||||
To make it easier for you, this repository contains a Makefile. It can be easily configured to customize running this container to your needs. Note that it does not provide a way to mount varnish_secret or custom configuration. Feel free to edit it to your needs
|
||||
```Makefile
|
||||
# Docker container tag
|
||||
IMAGE_NAME = varnish
|
||||
|
||||
# Port varnish will serve content on
|
||||
PORT = 8080
|
||||
|
||||
# Port you can later access with varnish admin CLI
|
||||
MANAGEMENT_PORT = 6082
|
||||
|
||||
# Here you can link your other containers to be used as backend servers
|
||||
# as container_name:hostname
|
||||
# please note that you have to add the hostname in the configuration too
|
||||
LINK =
|
||||
|
||||
# Addtional flags for Docker
|
||||
FLAGS =
|
||||
```
|
||||
|
||||
# Running in Openshift
|
||||
To run this container in OpenShift, you need to change the `RunAsUser` option in the `restricted` Security Context Constraint (SCC) from `MustRunAsRange` to `RunAsAny`. Do it by running:
|
||||
|
||||
```Shell
|
||||
$ oc login -u system:admin
|
||||
$ oc project default
|
||||
$ oc edit scc restricted
|
||||
```
|
||||
|
||||
Find `RunAsUser` and change its value from `MustRunAsRange` to `RunAsAny`. This is needed as varnish root proccess uses this privilege to sandbox child processes.
|
||||
|
||||
Then you can run `openshift-template.yml` in this repository:
|
||||
|
||||
```Shell
|
||||
$ oc login -u developer
|
||||
$ oc create -f openshift-template.yml
|
||||
```
|
||||
See also
|
||||
--------
|
||||
Dockerfile and other sources for this container image are available on
|
||||
https://github.com/sclorg/varnish-container.
|
||||
In that repository, Dockerfile for CentOS is called Dockerfile, Dockerfile
|
||||
for RHEL is called Dockerfile.rhel7.
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
#
|
||||
# This is an example VCL file for Varnish.
|
||||
#
|
||||
# It does not do anything by default, delegating control to the
|
||||
# builtin VCL. The builtin VCL is called when there is no explicit
|
||||
# return statement.
|
||||
#
|
||||
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
|
||||
# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples.
|
||||
|
||||
# Marker to tell the VCL compiler that this VCL has been adapted to the
|
||||
# new 4.0 format.
|
||||
vcl 4.0;
|
||||
|
||||
# Default backend definition. Set this to point to your content server.
|
||||
backend default {
|
||||
.host = "152.19.134.142";
|
||||
.port = "80";
|
||||
}
|
||||
|
||||
sub vcl_recv {
|
||||
# Happens before we check if we have this in cache already.
|
||||
#
|
||||
# Typically you clean up the request here, removing cookies you don't need,
|
||||
# rewriting the request, etc.
|
||||
}
|
||||
|
||||
sub vcl_backend_response {
|
||||
# Happens after we have read the response headers from the backend.
|
||||
#
|
||||
# Here you clean the response headers, removing silly Set-Cookie headers
|
||||
# and other mistakes your backend does.
|
||||
}
|
||||
|
||||
sub vcl_deliver {
|
||||
# Happens when we have all the pieces we need, and are about to send the
|
||||
# response to the client.
|
||||
#
|
||||
# You can do accounting or modifying the final object here.
|
||||
}
|
||||
1
help.md
Symbolic link
1
help.md
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
README.md
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
apiVersion: v1
|
||||
kind: Template
|
||||
metadata:
|
||||
name: varnish
|
||||
annotations:
|
||||
description: "Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy."
|
||||
tags: "load balancer, cache, varnish"
|
||||
labels:
|
||||
template: varnish
|
||||
group: varnish
|
||||
version: 1.0.0
|
||||
objects:
|
||||
- kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: varnish-front
|
||||
spec:
|
||||
selector:
|
||||
name: varnish-front
|
||||
ports:
|
||||
- name: varnish
|
||||
protocol: TCP
|
||||
port: 80
|
||||
targetPort: 6081
|
||||
nodePort: 0
|
||||
portalIP: ''
|
||||
type: ClusterIP
|
||||
- kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: varnish-admin
|
||||
spec:
|
||||
selector:
|
||||
name: varnish-admin
|
||||
ports:
|
||||
- name: varnish-admin
|
||||
protocol: TCP
|
||||
port: 6082
|
||||
targetPort: 6082
|
||||
nodePort: 0
|
||||
portalIP: ''
|
||||
type: ClusterIP
|
||||
- kind: ImageStream
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: varnish
|
||||
spec:
|
||||
dockerImageRepository: koscicz/varnish
|
||||
tags:
|
||||
- name: latest
|
||||
- kind: Route
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: varnish-front-route
|
||||
spec:
|
||||
host: ''
|
||||
to:
|
||||
kind: Service
|
||||
name: varnish-front
|
||||
- kind: DeploymentConfig
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: varnish
|
||||
spec:
|
||||
selector:
|
||||
name: varnish-front
|
||||
strategy:
|
||||
type: Rolling
|
||||
triggers:
|
||||
- type: ImageChange
|
||||
imageChangeParams:
|
||||
automatic: true
|
||||
containerNames:
|
||||
- varnish
|
||||
from:
|
||||
kind: ImageStreamTag
|
||||
name: varnish:latest
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
name: varnish-dummy
|
||||
labels:
|
||||
name: varnish-front
|
||||
spec:
|
||||
containers:
|
||||
- name: varnish
|
||||
image: varnish:latest
|
||||
ports:
|
||||
- containerPort: 6081
|
||||
164
root/help.1
164
root/help.1
|
|
@ -1,135 +1,105 @@
|
|||
.TH "VARNISH " "1" " Container Image Pages" "Jan Koscielniak" "June 20, 2017"
|
||||
.nh
|
||||
.ad l
|
||||
|
||||
|
||||
.SH NAME
|
||||
.TH Varnish Cache 5.0 HTTP reverse proxy Container image
|
||||
.PP
|
||||
varnish \- HTTP accelerator designed for content\-heavy dynamic web sites
|
||||
This container image includes Varnish 5.0 Cache server and a reverse proxy for OpenShift and general usage.
|
||||
Users can choose between RHEL and CentOS based images.
|
||||
The RHEL image is available in the Red Hat Container Catalog
|
||||
\[la]https://access.redhat.com/containers/#/registry.access.redhat.com/rhscl/varnish-5-rhel7\[ra]
|
||||
as registry.access.redhat.com/rhscl/varnish\-5\-rhel7.
|
||||
The CentOS image is then available on Docker Hub
|
||||
\[la]https://hub.docker.com/r/centos/varnish-5-centos7/\[ra]
|
||||
as centos/varnish\-5\-centos7.
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
.SH Description
|
||||
.PP
|
||||
This container image provides the varnish HTTP reverse proxy. It uses Fedora 26 as a base image.
|
||||
Varnish available as container is a base platform for
|
||||
running Varnish server or building Varnish\-based application.
|
||||
Varnish Cache stores web pages in memory so web servers don't have to create
|
||||
the same web page over and over again. Varnish Cache serves pages much faster
|
||||
than any application server, giving the website a significant speed up.
|
||||
|
||||
.PP
|
||||
Varnish secret file is generated each time the container is built, for better security. While this provides \fIsome\fP security, we strongly advise you always use your own secret (see below) or do not expose $MANAGEMENT\_PORT if you don't need it.
|
||||
The image can be used as a base image for other applications based on Varnish Cache 5.0 or using s2i tool.
|
||||
|
||||
|
||||
.SH USAGE
|
||||
.SH Usage
|
||||
.PP
|
||||
You can run this image in docker like this:
|
||||
To build a simple sample\-app
|
||||
\[la]https://github.com/sclorg/varnish-container/tree/generated/5/test/test-app\[ra] application
|
||||
using standalone S2I
|
||||
\[la]https://github.com/openshift/source-to-image\[ra] and then run the
|
||||
resulting image with Docker
|
||||
\[la]http://docker.io\[ra] execute:
|
||||
.IP \(bu 2
|
||||
|
||||
.PP
|
||||
\fBFor RHEL based image\fP
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
# docker run \-p $PORT:6081
|
||||
$ docker pull registry.access.redhat.com/rhscl/varnish\-5\-rhel7
|
||||
$ s2i build https://github.com/sclorg/varnish\-container.git \-\-context\-dir=5/test/test\-app/ registry.access.redhat.com/rhscl/varnish\-5\-rhel7 sample\-server
|
||||
$ docker run \-p 8080:8080 sample\-server
|
||||
|
||||
.fi
|
||||
.RE
|
||||
.IP \(bu 2
|
||||
|
||||
.PP
|
||||
\fBFor CentOS based image\fP
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
$ docker pull centos/varnish\-5\-centos7
|
||||
$ s2i build https://github.com/sclorg/varnish\-container.git \-\-context\-dir=5/test/test\-app/ centos/varnish\-5\-centos7 sample\-server
|
||||
$ docker run \-p 8080:8080 sample\-server
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.PP
|
||||
This is the basic execution of the container. $PORT is the port of the varnish frontend on which it will serve content. Varnish has it's own admin CLI (see $MANAGEMENT\_PORT below). To access it, you'll need the varnish secret file. Please refer to varnish documentation on how to generate it. You can mount your secret file, that has to be named varnish\_secret like this:
|
||||
\fBAccessing the application:\fP
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
# docker run \-p $PORT:6081 \-p $MANAGEMENT\_PORT:6082 \-v $SECRET\_DIR:/varnish\_secret/
|
||||
$ curl 127.0.0.1:8080
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.SH Configuration
|
||||
.PP
|
||||
If that gives you an error, it might be due to SELinux, you can then apply the following:
|
||||
No further configuration is required.
|
||||
|
||||
.SH S2I build support
|
||||
.PP
|
||||
The Varnish Cache 5.0 Container image supports the S2I tool (see Usage section).
|
||||
Note that the default.vcl configuration file in the directory accessed by S2I needs
|
||||
to be in the VCL format.
|
||||
|
||||
.SH Environment variables and volumes
|
||||
.PP
|
||||
No special environment variables or volumes available.
|
||||
|
||||
.SH Troubleshooting
|
||||
.PP
|
||||
Varnish logs into standard output, so the log is available in the container log. The log can be examined by running:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
# chcon \-Rt svirt\_sandbox\_file\_t $SECRET\_DIR
|
||||
docker logs <container>
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.SH See also
|
||||
.PP
|
||||
If you want to use your configuration instead of the default one, name it default.vcl and mount it like this:
|
||||
Dockerfile and other sources for this container image are available on
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
# docker run \-p $PORT:6081 \-v $CONFIG\_DIR:/varnish\_config/
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.PP
|
||||
Where $CONFIG\_DIR is a directory that contains default.vcl file.
|
||||
|
||||
.PP
|
||||
You can also link containers which you can use as backend servers. You need to run the container you want to use as backend, get it's name or hash, and then edit the configuration file with a hostname you choose for the container. Then run it like this:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
# docker run \-p $PORT:6081 \-\-link container\_name:hostname
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.PP
|
||||
Image can also be run in Openshift. You can obtain the template in the repository of this image \-
|
||||
\[la]https://github.com/container-images/nginx\[ra]\&. You also need to have SCC RunAsUser set to RunAsAny. Then run:
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
# oc create \-f openshift\-template.yml
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
|
||||
.SH ENVIRONMENT VARIABLES
|
||||
.PP
|
||||
There are no environment variables to be set.
|
||||
|
||||
|
||||
.SH SECURITY IMPLICATIONS
|
||||
.PP
|
||||
\-p $PORT:6081
|
||||
Exposes port 6081 on the container and forwards it to $PORT on the host. This is the varnish frontend.
|
||||
|
||||
.PP
|
||||
\-p $MANAGEMENT\_PORT:6082
|
||||
Exposes port 6082 on the container and forwards it to $MANAGEMENT\_PORT on the host. This is varnish admin CLI.
|
||||
|
||||
.PP
|
||||
\-v $SECRET\_DIR:/varnish/
|
||||
Mounts a directory with varnish\_secret file, that is used for securing the admin CLI.
|
||||
|
||||
.PP
|
||||
\-v $CONFIG\_DIR:/varnish\_config/
|
||||
Mounts a directory with default.vcl file, which is a configuration file for varnish.
|
||||
|
||||
.PP
|
||||
\-\-link container\_name:hostname
|
||||
Links another running container and assigns it a hostname. That hostname is used in varnish config to identify the container as a backend server
|
||||
|
||||
.PP
|
||||
This container runs as root user.
|
||||
|
||||
|
||||
.SH HISTORY
|
||||
.PP
|
||||
Similar to a Changelog of sorts which can be as detailed as the maintainer wishes.
|
||||
|
||||
|
||||
.SH SEE ALSO
|
||||
.PP
|
||||
Github page for this container with detailed description:
|
||||
\[la]https://github.com/container-images/varnish\[ra]
|
||||
\[la]https://github.com/sclorg/varnish-container\[ra]\&.
|
||||
In that repository, Dockerfile for CentOS is called Dockerfile, Dockerfile
|
||||
for RHEL is called Dockerfile.rhel7.
|
||||
|
|
|
|||
66
root/help.md
66
root/help.md
|
|
@ -1,66 +0,0 @@
|
|||
% VARNISH (1) Container Image Pages
|
||||
% Jan Koscielniak
|
||||
% September 5, 2017
|
||||
|
||||
# NAME
|
||||
varnish - HTTP accelerator designed for content-heavy dynamic web sites
|
||||
|
||||
# DESCRIPTION
|
||||
This container image provides the varnish HTTP reverse proxy. It uses Fedora 26 as a base image.
|
||||
|
||||
Varnish secret file is generated each time the container is built, for better security. While this provides *some* security, we strongly advise you always use your own secret (see below) or do not expose $MANAGEMENT_PORT if you don't need it.
|
||||
|
||||
# USAGE
|
||||
You can run this image in docker like this:
|
||||
|
||||
# docker run -p $PORT:6081
|
||||
|
||||
This is the basic execution of the container. $PORT is the port of the varnish frontend on which it will serve content. Varnish has it's own admin CLI (see $MANAGEMENT_PORT below). To access it, you'll need the varnish secret file. Please refer to varnish documentation on how to generate it. You can mount your secret file, that has to be named varnish_secret like this:
|
||||
|
||||
# docker run -p $PORT:6081 -p $MANAGEMENT_PORT:6082 -v $SECRET_DIR:/varnish_secret/
|
||||
|
||||
If that gives you an error, it might be due to SELinux, you can then apply the following:
|
||||
|
||||
# chcon -Rt svirt_sandbox_file_t $SECRET_DIR
|
||||
|
||||
If you want to use your configuration instead of the default one, name it default.vcl and mount it like this:
|
||||
|
||||
# docker run -p $PORT:6081 -v $CONFIG_DIR:/varnish_config/
|
||||
|
||||
Where $CONFIG_DIR is a directory that contains default.vcl file.
|
||||
|
||||
You can also link containers which you can use as backend servers. You need to run the container you want to use as backend, get it's name or hash, and then edit the configuration file with a hostname you choose for the container. Then run it like this:
|
||||
|
||||
# docker run -p $PORT:6081 --link container_name:hostname
|
||||
|
||||
|
||||
Image can also be run in Openshift. You can obtain the template in the repository of this image - https://github.com/container-images/nginx. You also need to have SCC RunAsUser set to RunAsAny. Then run:
|
||||
|
||||
# oc create -f openshift-template.yml
|
||||
|
||||
# ENVIRONMENT VARIABLES
|
||||
There are no environment variables to be set.
|
||||
|
||||
# SECURITY IMPLICATIONS
|
||||
-p $PORT:6081
|
||||
Exposes port 6081 on the container and forwards it to $PORT on the host. This is the varnish frontend.
|
||||
|
||||
-p $MANAGEMENT_PORT:6082
|
||||
Exposes port 6082 on the container and forwards it to $MANAGEMENT_PORT on the host. This is varnish admin CLI.
|
||||
|
||||
-v $SECRET_DIR:/varnish/
|
||||
Mounts a directory with varnish_secret file, that is used for securing the admin CLI.
|
||||
|
||||
-v $CONFIG_DIR:/varnish_config/
|
||||
Mounts a directory with default.vcl file, which is a configuration file for varnish.
|
||||
|
||||
--link container_name:hostname
|
||||
Links another running container and assigns it a hostname. That hostname is used in varnish config to identify the container as a backend server
|
||||
|
||||
This container runs as root user.
|
||||
|
||||
# HISTORY
|
||||
Similar to a Changelog of sorts which can be as detailed as the maintainer wishes.
|
||||
|
||||
# SEE ALSO
|
||||
Github page for this container with detailed description: https://github.com/container-images/varnish
|
||||
9
root/opt/app-root/etc/generate_container_user
Normal file
9
root/opt/app-root/etc/generate_container_user
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Set current user in nss_wrapper
|
||||
PASSWD_DIR="${APP_ROOT}/etc"
|
||||
|
||||
export USER_ID=$(id -u)
|
||||
export GROUP_ID=$(id -g)
|
||||
envsubst < ${PASSWD_DIR}/passwd.template > ${PASSWD_DIR}/passwd
|
||||
export LD_PRELOAD=libnss_wrapper.so
|
||||
export NSS_WRAPPER_PASSWD=${PASSWD_DIR}/passwd
|
||||
export NSS_WRAPPER_GROUP=/etc/group
|
||||
15
root/opt/app-root/etc/passwd.template
Normal file
15
root/opt/app-root/etc/passwd.template
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
root:x:0:0:root:/root:/bin/bash
|
||||
bin:x:1:1:bin:/bin:/sbin/nologin
|
||||
daemon:x:2:2:daemon:/sbin:/sbin/nologin
|
||||
adm:x:3:4:adm:/var/adm:/sbin/nologin
|
||||
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
|
||||
sync:x:5:0:sync:/sbin:/bin/sync
|
||||
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
|
||||
halt:x:7:0:halt:/sbin:/sbin/halt
|
||||
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
|
||||
operator:x:11:0:operator:/root:/sbin/nologin
|
||||
games:x:12:100:games:/usr/games:/sbin/nologin
|
||||
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
|
||||
nobody:x:99:99:Nobody:/:/sbin/nologin
|
||||
default:x:${USER_ID}:${GROUP_ID}:Default Application User:${HOME}:/sbin/nologin
|
||||
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
|
||||
3
root/opt/app-root/etc/scl_enable
Normal file
3
root/opt/app-root/etc/scl_enable
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# This will make scl collection binaries work out of box.
|
||||
unset BASH_ENV PROMPT_COMMAND ENV
|
||||
source scl_source enable rh-varnish5
|
||||
22
s2i/bin/assemble
Executable file
22
s2i/bin/assemble
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "---> Copying varnish configuration files..."
|
||||
rm -rf "${VARNISH_CONFIGURATION_PATH}/default.vcl"
|
||||
cp -Rfv /tmp/src/. "${VARNISH_CONFIGURATION_PATH}"
|
||||
|
||||
if [ ! -f "${VARNISH_CONFIGURATION_PATH}/default.vcl" ]; then
|
||||
echo "Error: The varnish configuration must contain 'default.vcl' file."
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -f "${VARNISH_CONFIGURATION_PATH}/varnish.params" ]; then
|
||||
echo "Error: The varnish configuration must contain 'varnish.params' file."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat "${VARNISH_CONFIGURATION_PATH}/default.vcl"
|
||||
|
||||
# Fix source directory permissions
|
||||
fix-permissions ./
|
||||
fix-permissions ${VARNISH_CONFIGURATION_PATH}
|
||||
32
s2i/bin/run
Executable file
32
s2i/bin/run
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /opt/app-root/etc/generate_container_user
|
||||
|
||||
set -e
|
||||
|
||||
. ${VARNISH_CONFIGURATION_PATH}/varnish.params
|
||||
|
||||
VERSION=$(varnishd -V 2>&1 | egrep -o "varnish-[0-9]")
|
||||
|
||||
VARNISH_TTL=${VARNISH_TTL:-120}
|
||||
|
||||
if [ "${VERSION}" == "varnish-4" ]; then
|
||||
PORT_EXPOSE="-a :8080,:8443"
|
||||
USER_GROUP='-u default -g root'
|
||||
elif [ "${VERSION}" == "varnish-5" ]; then
|
||||
PORT_EXPOSE="-a :8080 -a :8443"
|
||||
USER_GROUP='-j unix,user=default,ccgroup=root'
|
||||
else
|
||||
echo "Unsupported version of varnishd: ${VERSION}"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
exec varnishd \
|
||||
-F \
|
||||
-f $VARNISH_VCL_CONF \
|
||||
${PORT_EXPOSE} \
|
||||
-T 127.0.0.1:8081 \
|
||||
-t $VARNISH_TTL \
|
||||
-S $VARNISH_SECRET_FILE \
|
||||
-s $VARNISH_STORAGE \
|
||||
$DAEMON_OPTS
|
||||
18
s2i/bin/usage
Executable file
18
s2i/bin/usage
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
DISTRO=`cat /etc/*-release | grep ^ID= | sed s/ID=// | tr -d '"'`
|
||||
IMAGE=centos/varnish-5-$DISTRO
|
||||
[[ $DISTRO =~ rhel* ]] && IMAGE=rhscl/varnish-5-$DISTRO
|
||||
[[ $DISTRO =~ fedora* ]] && IMAGE=${FGC}/varnish
|
||||
|
||||
cat <<EOF
|
||||
This is a S2I ${IMAGE_DESCRIPTION} ${DISTRO} base image:
|
||||
To use it, install S2I: https://github.com/openshift/source-to-image
|
||||
|
||||
Sample invocation:
|
||||
|
||||
s2i build https://github.com/sclorg/varnish-container.git --context-dir=5/test/test-app/ ${IMAGE} varnish-sample-app
|
||||
|
||||
You can then run the resulting image via:
|
||||
docker run -p 8080:8080 varnish-sample-app
|
||||
EOF
|
||||
0
sources
0
sources
200
test/run
Executable file
200
test/run
Executable file
|
|
@ -0,0 +1,200 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# The 'run' performs a simple test that verifies that S2I image.
|
||||
# The main focus here is to excersise the S2I scripts.
|
||||
#
|
||||
# IMAGE_NAME specifies a name of the candidate image used for testing.
|
||||
# The image has to be available before this script is executed.
|
||||
#
|
||||
IMAGE_NAME=${IMAGE_NAME}
|
||||
|
||||
# TODO: Make command compatible for Mac users
|
||||
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"
|
||||
image_dir=$(readlink -zf ${test_dir}/..)
|
||||
|
||||
. "$test_dir/test-lib.sh"
|
||||
|
||||
# TODO: This should be part of the image metadata
|
||||
test_port=8080
|
||||
|
||||
info() {
|
||||
echo -e "\n\e[1m[INFO] $@...\e[0m\n"
|
||||
}
|
||||
|
||||
image_exists() {
|
||||
docker inspect $1 &>/dev/null
|
||||
}
|
||||
|
||||
container_exists() {
|
||||
image_exists $(cat $cid_file)
|
||||
}
|
||||
|
||||
container_ip() {
|
||||
docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file)
|
||||
}
|
||||
|
||||
run_s2i_build() {
|
||||
ct_s2i_build_as_df file://${test_dir}/test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp ${s2i_args}
|
||||
}
|
||||
|
||||
prepare() {
|
||||
if ! image_exists ${IMAGE_NAME}; then
|
||||
echo "ERROR: The image ${IMAGE_NAME} must exist before this script is executed."
|
||||
exit 1
|
||||
fi
|
||||
# TODO: S2I build require the application is a valid 'GIT' repository, we
|
||||
# should remove this restriction in the future when a file:// is used.
|
||||
info "Build the test application image"
|
||||
pushd ${test_dir}/test-app >/dev/null
|
||||
git init
|
||||
git config user.email "build@localhost" && git config user.name "builder"
|
||||
git add -A && git commit -m "Sample commit"
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
run_test_application() {
|
||||
run_args=${CONTAINER_ARGS:-}
|
||||
docker run --user=100001 ${run_args} --cidfile=${cid_file} ${IMAGE_NAME}-testapp
|
||||
}
|
||||
|
||||
cleanup_test_app() {
|
||||
info "Cleaning up the test application"
|
||||
if [ -f $cid_file ]; then
|
||||
if container_exists; then
|
||||
docker stop $(cat $cid_file)
|
||||
docker rm $(cat $cid_file)
|
||||
fi
|
||||
rm $cid_file
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
info "Cleaning up the test application image"
|
||||
if image_exists ${IMAGE_NAME}-testapp; then
|
||||
docker rmi -f ${IMAGE_NAME}-testapp
|
||||
fi
|
||||
rm -rf ${test_dir}/test-app/.git
|
||||
}
|
||||
|
||||
check_result() {
|
||||
local result="$1"
|
||||
if [[ "$result" != "0" ]]; then
|
||||
info "TEST FAILED (${result})"
|
||||
cleanup
|
||||
exit $result
|
||||
fi
|
||||
}
|
||||
|
||||
wait_for_cid() {
|
||||
local max_attempts=10
|
||||
local sleep_time=1
|
||||
local attempt=1
|
||||
local result=1
|
||||
info "Waiting for application container to start"
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
[ -f $cid_file ] && [ -s $cid_file ] && break
|
||||
attempt=$(( $attempt + 1 ))
|
||||
sleep $sleep_time
|
||||
done
|
||||
}
|
||||
|
||||
test_s2i_usage() {
|
||||
info "Testing 's2i usage'"
|
||||
ct_s2i_usage ${IMAGE_NAME} ${s2i_args} &>/dev/null
|
||||
}
|
||||
|
||||
test_docker_run_usage() {
|
||||
info "Testing 'docker run' usage"
|
||||
docker run ${IMAGE_NAME} &>/dev/null
|
||||
}
|
||||
|
||||
test_scl_usage() {
|
||||
local run_cmd="$1"
|
||||
local expected="$2"
|
||||
|
||||
info "Testing the image SCL enable"
|
||||
out=$(docker run --rm ${IMAGE_NAME} /bin/bash -c "${run_cmd} 2>&1")
|
||||
if ! echo "${out}" | grep -q "${expected}"; then
|
||||
echo "ERROR[/bin/bash -c "${run_cmd}"] Expected '${expected}', got '${out}'"
|
||||
return 1
|
||||
fi
|
||||
out=$(docker exec $(cat ${cid_file}) /bin/bash -c "${run_cmd}" 2>&1)
|
||||
if ! echo "${out}" | grep -q "${expected}"; then
|
||||
echo "ERROR[exec /bin/bash -c "${run_cmd}"] Expected '${expected}', got '${out}'"
|
||||
return 1
|
||||
fi
|
||||
out=$(docker exec $(cat ${cid_file}) /bin/sh -ic "${run_cmd}" 2>&1)
|
||||
if ! echo "${out}" | grep -q "${expected}"; then
|
||||
echo "ERROR[exec /bin/sh -ic "${run_cmd}"] Expected '${expected}', got '${out}'"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
test_connection() {
|
||||
cat $cid_file
|
||||
info "Testing the HTTP connection (http://$(container_ip):${test_port})"
|
||||
local max_attempts=10
|
||||
local sleep_time=1
|
||||
local attempt=1
|
||||
local result=1
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
response=$(curl -s -w "%{redirect_url}" -H "Host:oldexample.com" http://$(container_ip):${test_port}/)
|
||||
echo "${response}"
|
||||
status=$?
|
||||
if [ $status -eq 0 ]; then
|
||||
if echo "${response}" | grep -q "http://example.org"; then
|
||||
result=0
|
||||
break
|
||||
else
|
||||
echo "Response: ${response}"
|
||||
fi
|
||||
fi
|
||||
attempt=$(( $attempt + 1 ))
|
||||
sleep $sleep_time
|
||||
done
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
test_application() {
|
||||
# Verify that the HTTP connection can be established to test application container
|
||||
run_test_application &
|
||||
|
||||
# Wait for the container to write it's CID file
|
||||
wait_for_cid
|
||||
|
||||
test_scl_usage "varnishd -V" "varnish-$VERSION"
|
||||
check_result $?
|
||||
|
||||
test_connection
|
||||
check_result $?
|
||||
cleanup_test_app
|
||||
}
|
||||
|
||||
cid_file=$(mktemp -u --suffix=.cid)
|
||||
|
||||
# Since we built the candidate image locally, we don't want S2I attempt to pull
|
||||
# it from Docker hub
|
||||
s2i_args="--pull-policy=never"
|
||||
|
||||
prepare
|
||||
run_s2i_build
|
||||
check_result $?
|
||||
|
||||
# Verify the 'usage' script is working properly when running the base image with 's2i usage ...'
|
||||
test_s2i_usage
|
||||
check_result $?
|
||||
|
||||
# Verify the 'usage' script is working properly when running the base image with 'docker run ...'
|
||||
test_docker_run_usage
|
||||
check_result $?
|
||||
|
||||
# Test application with default uid
|
||||
test_application
|
||||
|
||||
# Test application with random uid
|
||||
CONTAINER_ARGS="--user 12345" test_application
|
||||
cleanup
|
||||
|
||||
info "All tests finished successfully."
|
||||
16
test/test-app/default.vcl
Normal file
16
test/test-app/default.vcl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
vcl 4.0;
|
||||
backend default {
|
||||
.host = "127.0.0.1";
|
||||
.port = "80";
|
||||
}
|
||||
|
||||
sub vcl_recv {
|
||||
return(synth(301, "Page moved"));
|
||||
}
|
||||
|
||||
sub vcl_synth {
|
||||
if (resp.status == 301) {
|
||||
set resp.http.Location = "http://example.org";
|
||||
return (deliver);
|
||||
}
|
||||
}
|
||||
507
test/test-lib.sh
Normal file
507
test/test-lib.sh
Normal file
|
|
@ -0,0 +1,507 @@
|
|||
#
|
||||
# Test a container image.
|
||||
#
|
||||
# Always use sourced from a specific container testfile
|
||||
#
|
||||
# reguires definition of CID_FILE_DIR
|
||||
# CID_FILE_DIR=$(mktemp --suffix=<container>_test_cidfiles -d)
|
||||
# reguires definition of TEST_LIST
|
||||
# TEST_LIST="\
|
||||
# ctest_container_creation
|
||||
# ctest_doc_content"
|
||||
|
||||
# Container CI tests
|
||||
# abbreviated as "ct"
|
||||
|
||||
# may be redefined in the specific container testfile
|
||||
EXPECTED_EXIT_CODE=0
|
||||
|
||||
# ct_cleanup
|
||||
# --------------------
|
||||
# Cleans up containers used during tests. Stops and removes all containers
|
||||
# referenced by cid_files in CID_FILE_DIR. Dumps logs if a container exited
|
||||
# unexpectedly. Removes the cid_files and CID_FILE_DIR as well.
|
||||
# Uses: $CID_FILE_DIR - path to directory containing cid_files
|
||||
# Uses: $EXPECTED_EXIT_CODE - expected container exit code
|
||||
function ct_cleanup() {
|
||||
for cid_file in $CID_FILE_DIR/* ; do
|
||||
local container=$(cat $cid_file)
|
||||
|
||||
: "Stopping and removing container $container..."
|
||||
docker stop $container
|
||||
exit_status=$(docker inspect -f '{{.State.ExitCode}}' $container)
|
||||
if [ "$exit_status" != "$EXPECTED_EXIT_CODE" ]; then
|
||||
: "Dumping logs for $container"
|
||||
docker logs $container
|
||||
fi
|
||||
docker rm -v $container
|
||||
rm $cid_file
|
||||
done
|
||||
rmdir $CID_FILE_DIR
|
||||
: "Done."
|
||||
}
|
||||
|
||||
# ct_enable_cleanup
|
||||
# --------------------
|
||||
# Enables automatic container cleanup after tests.
|
||||
function ct_enable_cleanup() {
|
||||
trap ct_cleanup EXIT SIGINT
|
||||
}
|
||||
|
||||
# ct_get_cid [name]
|
||||
# --------------------
|
||||
# Prints container id from cid_file based on the name of the file.
|
||||
# Argument: name - name of cid_file where the container id will be stored
|
||||
# Uses: $CID_FILE_DIR - path to directory containing cid_files
|
||||
function ct_get_cid() {
|
||||
local name="$1" ; shift || return 1
|
||||
echo $(cat "$CID_FILE_DIR/$name")
|
||||
}
|
||||
|
||||
# ct_get_cip [id]
|
||||
# --------------------
|
||||
# Prints container ip address based on the container id.
|
||||
# Argument: id - container id
|
||||
function ct_get_cip() {
|
||||
local id="$1" ; shift
|
||||
docker inspect --format='{{.NetworkSettings.IPAddress}}' $(ct_get_cid "$id")
|
||||
}
|
||||
|
||||
# ct_wait_for_cid [cid_file]
|
||||
# --------------------
|
||||
# Holds the execution until the cid_file is created. Usually run after container
|
||||
# creation.
|
||||
# Argument: cid_file - name of the cid_file that should be created
|
||||
function ct_wait_for_cid() {
|
||||
local cid_file=$1
|
||||
local max_attempts=10
|
||||
local sleep_time=1
|
||||
local attempt=1
|
||||
local result=1
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
[ -f $cid_file ] && [ -s $cid_file ] && return 0
|
||||
: "Waiting for container start..."
|
||||
attempt=$(( $attempt + 1 ))
|
||||
sleep $sleep_time
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# ct_assert_container_creation_fails [container_args]
|
||||
# --------------------
|
||||
# The invocation of docker run should fail based on invalid container_args
|
||||
# passed to the function. Returns 0 when container fails to start properly.
|
||||
# Argument: container_args - all arguments are passed directly to dokcer run
|
||||
# Uses: $CID_FILE_DIR - path to directory containing cid_files
|
||||
function ct_assert_container_creation_fails() {
|
||||
local ret=0
|
||||
local max_attempts=10
|
||||
local attempt=1
|
||||
local cid_file=assert
|
||||
set +e
|
||||
local old_container_args="${CONTAINER_ARGS-}"
|
||||
CONTAINER_ARGS="$@"
|
||||
ct_create_container $cid_file
|
||||
if [ $? -eq 0 ]; then
|
||||
local cid=$(ct_get_cid $cid_file)
|
||||
|
||||
while [ "$(docker inspect -f '{{.State.Running}}' $cid)" == "true" ] ; do
|
||||
sleep 2
|
||||
attempt=$(( $attempt + 1 ))
|
||||
if [ $attempt -gt $max_attempts ]; then
|
||||
docker stop $cid
|
||||
ret=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
exit_status=$(docker inspect -f '{{.State.ExitCode}}' $cid)
|
||||
if [ "$exit_status" == "0" ]; then
|
||||
ret=1
|
||||
fi
|
||||
docker rm -v $cid
|
||||
rm $CID_FILE_DIR/$cid_file
|
||||
fi
|
||||
[ ! -z $old_container_args ] && CONTAINER_ARGS="$old_container_args"
|
||||
set -e
|
||||
return $ret
|
||||
}
|
||||
|
||||
# ct_create_container [name, command]
|
||||
# --------------------
|
||||
# Creates a container using the IMAGE_NAME and CONTAINER_ARGS variables. Also
|
||||
# stores the container id to a cid_file located in the CID_FILE_DIR, and waits
|
||||
# for the creation of the file.
|
||||
# Argument: name - name of cid_file where the container id will be stored
|
||||
# Argument: command - optional command to be executed in the container
|
||||
# Uses: $CID_FILE_DIR - path to directory containing cid_files
|
||||
# Uses: $CONTAINER_ARGS - optional arguments passed directly to docker run
|
||||
# Uses: $IMAGE_NAME - name of the image being tested
|
||||
function ct_create_container() {
|
||||
local cid_file="$CID_FILE_DIR/$1" ; shift
|
||||
# create container with a cidfile in a directory for cleanup
|
||||
docker run --cidfile="$cid_file" -d ${CONTAINER_ARGS:-} $IMAGE_NAME "$@"
|
||||
ct_wait_for_cid $cid_file || return 1
|
||||
: "Created container $(cat $cid_file)"
|
||||
}
|
||||
|
||||
# ct_scl_usage_old [name, command, expected]
|
||||
# --------------------
|
||||
# Tests three ways of running the SCL, by looking for an expected string
|
||||
# in the output of the command
|
||||
# Argument: name - name of cid_file where the container id will be stored
|
||||
# Argument: command - executed inside the container
|
||||
# Argument: expected - string that is expected to be in the command output
|
||||
# Uses: $CID_FILE_DIR - path to directory containing cid_files
|
||||
# Uses: $IMAGE_NAME - name of the image being tested
|
||||
function ct_scl_usage_old() {
|
||||
local name="$1"
|
||||
local command="$2"
|
||||
local expected="$3"
|
||||
local out=""
|
||||
: " Testing the image SCL enable"
|
||||
out=$(docker run --rm ${IMAGE_NAME} /bin/bash -c "${command}")
|
||||
if ! echo "${out}" | grep -q "${expected}"; then
|
||||
echo "ERROR[/bin/bash -c "${command}"] Expected '${expected}', got '${out}'" >&2
|
||||
return 1
|
||||
fi
|
||||
out=$(docker exec $(ct_get_cid $name) /bin/bash -c "${command}" 2>&1)
|
||||
if ! echo "${out}" | grep -q "${expected}"; then
|
||||
echo "ERROR[exec /bin/bash -c "${command}"] Expected '${expected}', got '${out}'" >&2
|
||||
return 1
|
||||
fi
|
||||
out=$(docker exec $(ct_get_cid $name) /bin/sh -ic "${command}" 2>&1)
|
||||
if ! echo "${out}" | grep -q "${expected}"; then
|
||||
echo "ERROR[exec /bin/sh -ic "${command}"] Expected '${expected}', got '${out}'" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# ct_doc_content_old [strings]
|
||||
# --------------------
|
||||
# Looks for occurence of stirngs in the documentation files and checks
|
||||
# the format of the files. Files examined: help.1
|
||||
# Argument: strings - strings expected to appear in the documentation
|
||||
# Uses: $IMAGE_NAME - name of the image being tested
|
||||
function ct_doc_content_old() {
|
||||
local tmpdir=$(mktemp -d)
|
||||
local f
|
||||
: " Testing documentation in the container image"
|
||||
# Extract the help files from the container
|
||||
for f in help.1 ; do
|
||||
docker run --rm ${IMAGE_NAME} /bin/bash -c "cat /${f}" >${tmpdir}/$(basename ${f})
|
||||
# Check whether the files contain some important information
|
||||
for term in $@ ; do
|
||||
if ! cat ${tmpdir}/$(basename ${f}) | grep -F -q -e "${term}" ; then
|
||||
echo "ERROR: File /${f} does not include '${term}'." >&2
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
# Check whether the files use the correct format
|
||||
for term in TH PP SH ; do
|
||||
if ! grep -q "^\.${term}" ${tmpdir}/help.1 ; then
|
||||
echo "ERROR: /help.1 is probably not in troff or groff format, since '${term}' is missing." >&2
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
done
|
||||
: " Success!"
|
||||
}
|
||||
|
||||
|
||||
# ct_npm_works
|
||||
# --------------------
|
||||
# Checks existance of the npm tool and runs it.
|
||||
function ct_npm_works() {
|
||||
local tmpdir=$(mktemp -d)
|
||||
: " Testing npm in the container image"
|
||||
docker run --rm ${IMAGE_NAME} /bin/bash -c "npm --version" >${tmpdir}/version
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "ERROR: 'npm --version' does not work inside the image ${IMAGE_NAME}." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
docker run --rm ${IMAGE_NAME} /bin/bash -c "npm install jquery && test -f node_modules/jquery/src/jquery.js"
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "ERROR: npm could not install jquery inside the image ${IMAGE_NAME}." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
: " Success!"
|
||||
}
|
||||
|
||||
|
||||
# ct_path_append PATH_VARNAME DIRECTORY
|
||||
# -------------------------------------
|
||||
# Append DIRECTORY to VARIABLE of name PATH_VARNAME, the VARIABLE must consist
|
||||
# of colon-separated list of directories.
|
||||
ct_path_append ()
|
||||
{
|
||||
if eval "test -n \"\${$1-}\""; then
|
||||
eval "$1=\$2:\$$1"
|
||||
else
|
||||
eval "$1=\$2"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# ct_path_foreach PATH ACTION [ARGS ...]
|
||||
# --------------------------------------
|
||||
# For each DIR in PATH execute ACTION (path is colon separated list of
|
||||
# directories). The particular calls to ACTION will look like
|
||||
# '$ ACTION directory [ARGS ...]'
|
||||
ct_path_foreach ()
|
||||
{
|
||||
local dir dirlist action save_IFS
|
||||
save_IFS=$IFS
|
||||
IFS=:
|
||||
dirlist=$1
|
||||
action=$2
|
||||
shift 2
|
||||
for dir in $dirlist; do "$action" "$dir" "$@" ; done
|
||||
IFS=$save_IFS
|
||||
}
|
||||
|
||||
|
||||
# ct_run_test_list
|
||||
# --------------------
|
||||
# Execute the tests specified by TEST_LIST
|
||||
# Uses: $TEST_LIST - list of test names
|
||||
function ct_run_test_list() {
|
||||
for test_case in $TEST_LIST; do
|
||||
: "Running test $test_case"
|
||||
[ -f test/$test_case ] && source test/$test_case
|
||||
[ -f ../test/$test_case ] && source ../test/$test_case
|
||||
$test_case
|
||||
done;
|
||||
}
|
||||
|
||||
# ct_gen_self_signed_cert_pem
|
||||
# ---------------------------
|
||||
# Generates a self-signed PEM certificate pair into specified directory.
|
||||
# Argument: output_dir - output directory path
|
||||
# Argument: base_name - base name of the certificate files
|
||||
# Resulted files will be those:
|
||||
# <output_dir>/<base_name>-cert-selfsigned.pem -- public PEM cert
|
||||
# <output_dir>/<base_name>-key.pem -- PEM private key
|
||||
ct_gen_self_signed_cert_pem() {
|
||||
local output_dir=$1 ; shift
|
||||
local base_name=$1 ; shift
|
||||
mkdir -p ${output_dir}
|
||||
openssl req -newkey rsa:2048 -nodes -keyout ${output_dir}/${base_name}-key.pem -subj '/C=GB/ST=Berkshire/L=Newbury/O=My Server Company' > ${base_name}-req.pem
|
||||
openssl req -new -x509 -nodes -key ${output_dir}/${base_name}-key.pem -batch > ${output_dir}/${base_name}-cert-selfsigned.pem
|
||||
}
|
||||
|
||||
# ct_obtain_input FILE|DIR|URL
|
||||
# --------------------
|
||||
# Either copies a file or a directory to a tmp location for local copies, or
|
||||
# downloads the file from remote location.
|
||||
# Resulted file path is printed, so it can be later used by calling function.
|
||||
# Arguments: input - local file, directory or remote URL
|
||||
function ct_obtain_input() {
|
||||
local input=$1
|
||||
local extension="${input##*.}"
|
||||
|
||||
# Try to use same extension for the temporary file if possible
|
||||
[[ "${extension}" =~ ^[a-z0-9]*$ ]] && extension=".${extension}" || extension=""
|
||||
|
||||
local output=$(mktemp "/var/tmp/test-input-XXXXXX$extension")
|
||||
if [ -f "${input}" ] ; then
|
||||
cp -f "${input}" "${output}"
|
||||
elif [ -d "${input}" ] ; then
|
||||
rm -f "${output}"
|
||||
cp -r -LH "${input}" "${output}"
|
||||
elif echo "${input}" | grep -qe '^http\(s\)\?://' ; then
|
||||
curl "${input}" > "${output}"
|
||||
else
|
||||
echo "ERROR: file type not known: ${input}" >&2
|
||||
return 1
|
||||
fi
|
||||
echo "${output}"
|
||||
}
|
||||
|
||||
# ct_test_response
|
||||
# ----------------
|
||||
# Perform GET request to the application container, checks output with
|
||||
# a reg-exp and HTTP response code.
|
||||
# Argument: url - request URL path
|
||||
# Argument: expected_code - expected HTTP response code
|
||||
# Argument: body_regexp - PCRE regular expression that must match the response body
|
||||
# Argument: max_attempts - Optional number of attempts (default: 20), three seconds sleep between
|
||||
# Argument: ignore_error_attempts - Optional number of attempts when we ignore error output (default: 10)
|
||||
ct_test_response() {
|
||||
local url="$1"
|
||||
local expected_code="$2"
|
||||
local body_regexp="$3"
|
||||
local max_attempts=${4:-20}
|
||||
local ignore_error_attempts=${5:-10}
|
||||
|
||||
: " Testing the HTTP(S) response for <${url}>"
|
||||
local sleep_time=3
|
||||
local attempt=1
|
||||
local result=1
|
||||
local status
|
||||
local response_code
|
||||
local response_file=$(mktemp /tmp/ct_test_response_XXXXXX)
|
||||
while [ ${attempt} -le ${max_attempts} ]; do
|
||||
curl --connect-timeout 10 -s -w '%{http_code}' "${url}" >${response_file} && status=0 || status=1
|
||||
if [ ${status} -eq 0 ]; then
|
||||
response_code=$(cat ${response_file} | tail -c 3)
|
||||
if [ "${response_code}" -eq "${expected_code}" ]; then
|
||||
result=0
|
||||
fi
|
||||
cat ${response_file} | grep -qP -e "${body_regexp}" || result=1;
|
||||
# Some services return 40x code until they are ready, so let's give them
|
||||
# some chance and not end with failure right away
|
||||
# Do not wait if we already have expected outcome though
|
||||
if [ ${result} -eq 0 -o ${attempt} -gt ${ignore_error_attempts} -o ${attempt} -eq ${max_attempts} ] ; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
attempt=$(( ${attempt} + 1 ))
|
||||
sleep ${sleep_time}
|
||||
done
|
||||
rm -f ${response_file}
|
||||
return ${result}
|
||||
}
|
||||
|
||||
# ct_registry_from_os OS
|
||||
# ----------------
|
||||
# Transform operating system string [os] into registry url
|
||||
# Argument: OS - string containing the os version
|
||||
ct_registry_from_os() {
|
||||
local registry=""
|
||||
case $1 in
|
||||
rhel7)
|
||||
registry=registry.access.redhat.com
|
||||
;;
|
||||
*)
|
||||
registry=docker.io
|
||||
;;
|
||||
esac
|
||||
echo "$registry"
|
||||
}
|
||||
|
||||
# ct_assert_cmd_success CMD
|
||||
# ----------------
|
||||
# Evaluates [cmd] and fails if it does not succeed.
|
||||
# Argument: CMD - Command to be run
|
||||
function ct_assert_cmd_success() {
|
||||
echo "Checking '$*' for success ..."
|
||||
if ! eval "$@" &>/dev/null; then
|
||||
echo " FAIL"
|
||||
return 1
|
||||
fi
|
||||
echo " PASS"
|
||||
return 0
|
||||
}
|
||||
|
||||
# ct_assert_cmd_failure CMD
|
||||
# ----------------
|
||||
# Evaluates [cmd] and fails if it succeeds.
|
||||
# Argument: CMD - Command to be run
|
||||
function ct_assert_cmd_failure() {
|
||||
echo "Checking '$*' for failure ..."
|
||||
if eval "$@" &>/dev/null; then
|
||||
echo " FAIL"
|
||||
return 1
|
||||
fi
|
||||
echo " PASS"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
# ct_random_string [LENGTH=10]
|
||||
# ----------------------------
|
||||
# Generate pseudorandom alphanumeric string of LENGTH bytes, the
|
||||
# default length is 10. The string is printed on stdout.
|
||||
ct_random_string()
|
||||
(
|
||||
export LC_ALL=C
|
||||
dd if=/dev/urandom count=1 bs=10k 2>/dev/null \
|
||||
| tr -dc 'a-z0-9' \
|
||||
| fold -w "${1-10}" \
|
||||
| head -n 1
|
||||
)
|
||||
|
||||
# ct_s2i_usage IMG_NAME [S2I_ARGS]
|
||||
# ----------------------------
|
||||
# Create a container and run the usage script inside
|
||||
# Argument: IMG_NAME - name of the image to be used for the container run
|
||||
# Argument: S2I_ARGS - Additional list of source-to-image arguments, currently unused.
|
||||
ct_s2i_usage()
|
||||
{
|
||||
local img_name=$1; shift
|
||||
local s2i_args="$*";
|
||||
local usage_command="/usr/libexec/s2i/usage"
|
||||
docker run --rm "$img_name" bash -c "$usage_command"
|
||||
}
|
||||
|
||||
# ct_s2i_build_as_df APP_PATH SRC_IMAGE DST_IMAGE [S2I_ARGS]
|
||||
# ----------------------------
|
||||
# Create a new s2i app image from local sources in a similar way as source-to-image would have used.
|
||||
# Argument: APP_PATH - local path to the app sources to be used in the test
|
||||
# Argument: SRC_IMAGE - image to be used as a base for the s2i build
|
||||
# Argument: DST_IMAGE - image name to be used during the tagging of the s2i build result
|
||||
# Argument: S2I_ARGS - Additional list of source-to-image arguments.
|
||||
# Only used to check for pull-policy=never and environment variable definitions.
|
||||
ct_s2i_build_as_df()
|
||||
{
|
||||
local app_path=$1; shift
|
||||
local src_image=$1; shift
|
||||
local dst_image=$1; shift
|
||||
local s2i_args="$*";
|
||||
local local_app=upload/src/
|
||||
local local_scripts=upload/scripts/
|
||||
local user_id=
|
||||
local df_name=
|
||||
local tmpdir=
|
||||
# Use /tmp to not pollute cwd
|
||||
tmpdir=$(mktemp -d)
|
||||
df_name=$(mktemp -p "$tmpdir" Dockerfile.XXXX)
|
||||
pushd "$tmpdir"
|
||||
# Check if the image is available locally and try to pull it if it is not
|
||||
docker images "$src_image" &>/dev/null || echo "$s2i_args" | grep -q "pull-policy=never" || docker pull "$src_image"
|
||||
user_id=$(docker inspect -f "{{.ContainerConfig.User}}" "$src_image")
|
||||
# Strip file:// from APP_PATH and copy its contents into current context
|
||||
mkdir -p "$local_app"
|
||||
cp -r "${app_path/file:\/\//}/." "$local_app"
|
||||
[ -d "$local_app/.s2i/bin/" ] && mv "$local_app/.s2i/bin" "$local_scripts"
|
||||
# Create a Dockerfile named df_name and fill it with proper content
|
||||
#FIXME: Some commands could be combined into a single layer but not sure if worth the trouble for testing purposes
|
||||
cat <<EOF >"$df_name"
|
||||
FROM $src_image
|
||||
LABEL "io.openshift.s2i.build.image"="$src_image" \\
|
||||
"io.openshift.s2i.build.source-location"="$app_path"
|
||||
USER root
|
||||
COPY $local_app /tmp/src
|
||||
EOF
|
||||
[ -d "$local_scripts" ] && echo "COPY $local_scripts /tmp/scripts" >> "$df_name" &&
|
||||
echo "RUN chown -R $user_id:0 /tmp/scripts" >>"$df_name"
|
||||
echo "RUN chown -R $user_id:0 /tmp/src" >>"$df_name"
|
||||
# Check for custom environment variables inside .s2i/ folder
|
||||
if [ -e "$local_app/.s2i/environment" ]; then
|
||||
# Remove any comments and add the contents as ENV commands to the Dockerfile
|
||||
sed '/^\s*#.*$/d' "$local_app/.s2i/environment" | while read -r line; do
|
||||
echo "ENV $line" >>"$df_name"
|
||||
done
|
||||
fi
|
||||
# Filter out env var definitions from $s2i_args and create Dockerfile ENV commands out of them
|
||||
echo "$s2i_args" | grep -o -e '\(-e\|--env\)[[:space:]=]\S*=\S*' | sed -e 's/-e /ENV /' -e 's/--env[ =]/ENV /' >>"$df_name"
|
||||
echo "USER $user_id" >>"$df_name"
|
||||
# If exists, run the custom assemble script, else default to /usr/libexec/s2i/assemble
|
||||
if [ -x "$local_scripts/assemble" ]; then
|
||||
echo "RUN /tmp/scripts/assemble" >>"$df_name"
|
||||
else
|
||||
echo "RUN /usr/libexec/s2i/assemble" >>"$df_name"
|
||||
fi
|
||||
# If exists, set the custom run script as CMD, else default to /usr/libexec/s2i/run
|
||||
if [ -x "$local_scripts/run" ]; then
|
||||
echo "CMD /tmp/scripts/run" >>"$df_name"
|
||||
else
|
||||
echo "CMD /usr/libexec/s2i/run" >>"$df_name"
|
||||
fi
|
||||
# Run the build and tag the result
|
||||
docker build -f "$df_name" -t "$dst_image" .
|
||||
popd
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
MODULE_LINT=/usr/share/moduleframework/tools/modulelint.py
|
||||
CMD=python -m avocado run --filter-by-tags=-WIP $(MODULE_LINT)
|
||||
#CMD=python -m avocado run --filter-by-tags=-WIP
|
||||
|
||||
test1:
|
||||
$(CMD) *.py
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
from avocado import main
|
||||
from avocado.core import exceptions
|
||||
from moduleframework import module_framework
|
||||
import urllib
|
||||
import os
|
||||
|
||||
|
||||
class SanityTest1(module_framework.AvocadoTest):
|
||||
"""
|
||||
:avocado: enable
|
||||
"""
|
||||
|
||||
def test1(self):
|
||||
self.start()
|
||||
conn = urllib.urlopen("http://localhost:" + str(self.getConfig()['service']['port']))
|
||||
code = conn.getcode()
|
||||
print ">>> Testing fedora.org as a backend"
|
||||
print ">>> Returned code: " + str(code)
|
||||
print conn.read()
|
||||
assert code == 200
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
document: modularity-testing
|
||||
version: 1
|
||||
name: varnish
|
||||
modulemd-url: https://raw.githubusercontent.com/container-images/varnish/master/varnish.yaml
|
||||
service:
|
||||
port: 6081
|
||||
packages:
|
||||
rpms:
|
||||
- varnish
|
||||
testdependecies:
|
||||
rpms:
|
||||
- nc
|
||||
module:
|
||||
docker:
|
||||
start: "docker run -it -p 6081:6081"
|
||||
source: https://github.com/container-images/varnish.git
|
||||
container: docker.io/modularitycontainers/varnish
|
||||
rpm:
|
||||
start: systemctl start varnish
|
||||
stop: systemctl stop varnish
|
||||
status: systemctl status varnish
|
||||
repos:
|
||||
- http://mirror.vutbr.cz/fedora/releases/26/Everything/x86_64/os/
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue