Skip to content

Commit

Permalink
Remove packages from registry Docker build (#583)
Browse files Browse the repository at this point in the history
The Dockerfile for the registry itself should not contain any packages. Instead it should be empty and there are other distributions with packages, see elastic/package-storage#86. This removes the packages from the default Docker build.

Few additional changes in the this PR:
  • Loading branch information
ruflin authored Jul 3, 2020
1 parent 8caa4d2 commit 0579a6e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 34 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ package-registry

.idea
build
public/*
49 changes: 21 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
# This Dockerfile allows to build the package-registry and packages together.
# It is decoupled from the packages and the registry even though for now both are in the same repository.
# This image contains the package-registry binary.
# It expects packages to be mounted under /packages/package-registry or have a config file loaded into /package-registry/config.yml

# Build binary
ARG GO_VERSION=1.14.2
FROM golang:${GO_VERSION}
FROM golang:${GO_VERSION} AS builder

# Get dependencies
RUN \
apt-get update \
&& apt-get install -y --no-install-recommends zip rsync \
&& rm -rf /var/lib/apt/lists/*
ENV GO111MODULE=on
COPY ./ /package-registry
WORKDIR /package-registry
RUN go build .

# Copy the package registry
COPY ./ /home/package-registry
WORKDIR /home/package-registry

ENV GO111MODULE=on
RUN go get -u github.com/magefile/mage
# Prepare all the packages to be built
RUN mage build
# Run binary
FROM centos:7

# Build binary
RUN go build .
# Get dependencies
RUN yum install -y zip rsync && yum clean all

# Move all files need to run to its own directory
# This will become useful for staged builds later on
RUN mkdir -p /registry/public # left for legacy purposes
RUN mkdir -p /registry/packages/package-storage
RUN mv package-registry /registry/
RUN cp -r build/package-storage/packages/* /registry/packages/package-storage/
RUN cp config.docker.yml /registry/config.yml
# Move binary from the builder image
COPY --from=builder /package-registry/package-registry /package-registry/package-registry

# Change to new working directory
WORKDIR /registry
WORKDIR /package-registry

# Clean up files not needed
RUN rm -rf /home/package-registry
# Get in config which expects packages in /packages
COPY config.docker.yml /package-registry/config.yml

# Start registry when container is run an expose it on port 8080
EXPOSE 8080

ENTRYPOINT ["./package-registry"]

# Make sure it's accessible from outside the container
CMD ["--address=0.0.0.0:8080"]

HEALTHCHECK --interval=1s --retries=30 CMD curl --silent --fail localhost:8080/health || exit 1

5 changes: 4 additions & 1 deletion config.docker.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
public_dir: ./public

# If users want to add their own packages, they should be put under
# /packages/package-registry or the config must be adjusted.
package_paths:
- ./packages/package-storage
- /packages/package-registry

cache_time.search: 10m
cache_time.categories: 10m
Expand Down
6 changes: 3 additions & 3 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func Build() error {
return err
}

err = fetchPackageStorage()
err = FetchPackageStorage()
if err != nil {
return err
}
return sh.Run("go", "build", ".")
}

func fetchPackageStorage() error {
func FetchPackageStorage() error {

// If storage directory does not exists, check it out
if _, err := os.Stat(storageRepoDir); os.IsNotExist(err) {
Expand All @@ -64,7 +64,7 @@ func fetchPackageStorage() error {

packageStorageRevision := os.Getenv("PACKAGE_STORAGE_REVISION")
if packageStorageRevision == "" {
packageStorageRevision = "master"
packageStorageRevision = "production"
}

err := sh.Run("git",
Expand Down
6 changes: 6 additions & 0 deletions main_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (
// and the setup command works as expected.
func TestSetup(t *testing.T) {

// Mage fetchPackageStorage is needed to pull in the packages from package-storage
err := sh.Run("mage", "fetchPackageStorage")
if err != nil {
t.Error(err)
}

currentDir, err := os.Getwd()
if err != nil {
t.Error(err)
Expand Down
5 changes: 4 additions & 1 deletion testing/environments/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ services:

package-registry:
build: ../..
image: docker.elastic.co/package-registry/package-registry:master
#image: docker.elastic.co/package-registry/package-registry:master
volumes:
- ./package-registry.config.yml:/package-registry/config.yml
- ../../build/package-storage/packages:/packages/package-storage
ports:
- "127.0.0.1:8080:8080"

6 changes: 6 additions & 0 deletions testing/environments/package-registry.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package_paths:
- /packages/package-storage

cache_time.search: 10s
cache_time.categories: 10s
cache_time.catch_all: 10s

0 comments on commit 0579a6e

Please sign in to comment.