Build step

The main idea is that, in the build phase, you prepare your code to run in a packaged way – in a Docker container that you built using a Dockerfile – via Heroku build packs.

For the eventmanager app, user1 created the following Dockerfile:

  FROM ruby:2
COPY . /var/www/ruby
WORKDIR /var/www/ruby
RUN bundle install
CMD ["ruby","eventmanager.rb"]
EXPOSE 5000/tcp

As you can see from the first line of the preceding code, it pulls a basic Ruby-enabled Debian Linux image. It copies all the source code to a directory and goes there. Then, a bundle install is run, which installs all the Ruby dependencies that are needed. Finally, it starts the eventmanager app using the CMD command and exposes port 5000 to the outside world. It has to expose port 5000 because the default Helm chart that is used to deploy to Kubernetes assumes this port to run the application. It will be wired to port 80 or 443 after deployment.

The following code is for the log when the build phase is started:

Running with gitlab-runner 11.8.0 (4745a6f3)
on runner-gitlab-runner-7fd79f558b-2wx96 _drEv8rS
Using Kubernetes namespace: gitlab-managed-apps
Using Kubernetes executor with image registry.gitlab.com/gitlab-org/cluster-integration/auto-build-image/master:stable ...
Waiting for pod gitlab-managed-apps/runner-drev8rs-project-3-concurrent-0fvjtb to be running, status is Pending
...

It runs the Kubernetes executor and waits for a pod to be available.

When that happens, the build script is run. First, a login to the GitLab registry for this project is attempted (we need to push the build there afterwards):

$ /build/build.sh
Logging to GitLab Container Registry with CI credentials...
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded
...

Then, the build of the Docker image will start:

Building Dockerfile-based application...
Sending build context to Docker daemon 113.7kB

Step 1/6 : FROM ruby:2-alpine
2-alpine: Pulling from library/ruby
...

The built container image is pushed to the Docker registry for the eventmanager project:

Successfully built 5bd173d74f67
Successfully tagged
...
Job succeeded

When the Docker container image is stored in the registry, the subsequent phases will use the image and pull it. This concludes the build step. The next step is to run the code quality scan.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.0.25