From 548e4150461ca3c3cd969069a3d92254d0c39800 Mon Sep 17 00:00:00 2001 From: Jose Torres <torres@balameb.com> Date: Sun, 13 Nov 2016 23:40:24 -0600 Subject: [PATCH] Adds sample app and Runners sections --- content/docker.md | 42 ++++++++++ content/gitlab-ci-yml.md | 166 ++++++++++++++++++++++++++++++++++++--- content/runners.md | 19 ++--- content/sample_app.md | 50 ++++-------- index.html | 33 +++++++- 5 files changed, 254 insertions(+), 56 deletions(-) create mode 100644 content/docker.md diff --git a/content/docker.md b/content/docker.md new file mode 100644 index 0000000..effa686 --- /dev/null +++ b/content/docker.md @@ -0,0 +1,42 @@ +## Docker + +Download and modify a Docker image: + +``` +docker images +docker run -t -i ruby:2.3 /bin/bash + +$ apt-get update +$ apt-get install nodejs -y +$ gem install bundler --no-ri --no-rdoc +# A Dockerfile is a great option for the following line or +# maybe integrate with our current CI script? +$ bundle install +$ exit + +# Log back in? +docker ps -a # and get container sha +docker start -i <container-sha> +``` + +---------- +## Create a custom image + +``` +# Commit a new image +docker commit -m "Adds dependencies" -a "Peter Parker" \ +<container-sha> registry.gitlab.com/<group-name>/projectname:v2 + +# Or commit the image and tag it later +docker tag <image id> <url>:<port>/<user/project>:<tag> + +# Login in to GitLab registry +# docker login registry.gitlab.com +docker login <url>:<port> + +# Push image to registry +# docker push registry.gitlab.com/gitlab-org/ci-training-sample +docker push <registry-url>/<group-name>/<project-name>:<tag> +``` + +[Back](#/agenda) diff --git a/content/gitlab-ci-yml.md b/content/gitlab-ci-yml.md index e461dbe..17a7a04 100644 --- a/content/gitlab-ci-yml.md +++ b/content/gitlab-ci-yml.md @@ -1,17 +1,165 @@ -## Configurations: gitlab-ci.yml +## Configurations: gitlab-ci.yml -- Choose a directory on you machine easy to access -- Create a workspace or development directory -- This is where we'll be working and adding content +---------- + +### Let's start building the app + +- What is the `gitlab-ci.yml` file? +- Review the file with CI Lint at Pipelines +- Our plan: + - Image + - Services + - Environments + - Stages + - Jobs +---------- + - Before and After Scripts + - Caching + - Artifacts & On Success + - Only and except + - When + - Pages + +---------- + +### Docker Image & Registry + +Use a public image: +``` +image: ruby:2.3 +``` +Use a custom image: +``` +image: "registry.gitlab.com/gitlab-org/ci-training-sample:ruby-and-gems" +``` + +---------- + +### Services and Variables + +- Pre defined vars: https://docs.gitlab.com/ce/ci/variables/README.html + +``` +services: + - postgres + +variables: + POSTGRES_DB: rails-sample-1_test + POSTGRES_USER: root + POSTGRES_PASSWORD: "" +``` +---------- + +### Stages + +- Default stages: build, test, deploy +- User can define any custom stage and any number of jobs per stage + +``` +stages: +- build +- test +- deploy +``` +---------- + +### Before and After Scripts + +``` +before_script: + - echo CI_BUILD_STAGE + - apt-get update + - apt-get install nodejs -y + - gem install bundler --no-ri --no-rdoc + - bundle install +``` +---------- + +### Caching + +``` +cache: + key: "%CI_BUILD_STAGE%/%CI_BUILD_REF_NAME%" + paths: + - vendor/ruby +``` + +---------- + +### Templates +- Anchors, aliases and merging with yml + +``` +.hidden_anchor: &ruby_info + script: + - echo ruby -v + - echo which ruby + +env_info: + <<: *ruby_info + stage: build +``` + +---------- + +### Artifacts & On Success + +``` +system_specs: + stage: build + script: + - echo "author:" + - echo GITLAB_USER_EMAIL + - touch system_info + - uname -a > system_info + artifacts: + when: on_success + paths: + - system_info +``` ---------- +### Tests and Manual trigger + +``` +rspec: + stage: test + when: manual + script: + - "sed -i 's/host:.*/host: postgres/g' config/database.yml" + - "sed -i 's/username:.*/username: root/g' config/database.yml" + - bundle exec rake db:migrate RAILS_ENV=test + - bundle exec rake spec ``` -mkdir ~/development -cd ~/development --or- +---------- + +### Environments, Only and Deploying -mkdir ~/workspace -cd ~/workspace +``` +pseudo-deploy: + stage: deploy + script: + - echo "Deploying ... not really" + only: + - production + environment: + name: production +``` + +---------- + +### Pages + +``` +pages: + stage: deploy + script: + - echo 'Publishing pages' + artifacts: + paths: + - public + only: + - master ``` diff --git a/content/runners.md b/content/runners.md index 82db032..f6c7eb5 100644 --- a/content/runners.md +++ b/content/runners.md @@ -1,17 +1,14 @@ ## Runners -- Choose a directory on you machine easy to access -- Create a workspace or development directory -- This is where we'll be working and adding content +- A runner is an isolated (virtual) machine that picks up builds through the +coordinator API of GitLab CI. ----------- +- You can create as many Runners as you need on different machines -``` -mkdir ~/development -cd ~/development +- The Runners screen --or- +- Specific vs Shared Runners -mkdir ~/workspace -cd ~/workspace -``` +- Installation vs registration + +- Tagged Runners diff --git a/content/sample_app.md b/content/sample_app.md index 3c55fd0..8e81974 100644 --- a/content/sample_app.md +++ b/content/sample_app.md @@ -1,44 +1,28 @@ ## Sample App - ---------- -## Docker - -Download and modify a Docker image: +### Main Objectives +- Build a web application on Ruby on Rails +- Create an integration workflow +- Automate deployments -``` -docker images -docker run -t -i ruby:2.3 /bin/bash +--- -$ apt-get update -$ apt-get install nodejs -y -$ gem install bundler --no-ri --no-rdoc -# A Dockerfile is a great option for the following line or -# maybe integrate with our current CI script? -$ bundle install -$ exit +### Complementary +- Project landing page +- Docker environment for build and development -# Log back in? -docker ps -a # and get container sha -docker start -i <container-sha> -``` +Note: +- Add some interesting context such as "we're getting hired to do ABC" ---------- -## Create a custom image - -docker tag <image id> <url>:<port>/<user/project>:<tag> - -``` -# Commit a new image -docker commit -m "Adds dependencies" -a "Peter Parker" \ -<container-sha> registry.gitlab.com/<group-name>/projectname:v2 -# Login in to GitLab registry -# docker login registry.gitlab.com -docker login <url>:<port> +### App and CI Tour -# Push image to registry -# docker push registry.gitlab.com/gitlab-org/ci-training-sample -docker push <registry-url>/<group-name>/<project-name>:<tag> -``` +- Review files and repository +- View CI badge +- Talk about the pipeline and builds +- Talk about environments +- Cycle Analytics +- Activating builds diff --git a/index.html b/index.html index 97a1ee6..a74db99 100644 --- a/index.html +++ b/index.html @@ -64,7 +64,7 @@ </section> <!-- Agenda --> - <section> + <section id="agenda"> <!-- nested agenda sections --> <section data-markdown> ## Agenda @@ -85,6 +85,16 @@ - Runners - Questions </section> + + <section data-markdown> + Complementary: + - [Docker](#/docker) + + Note: + - The docker item is a link to the slides + - The docker slides have a back link to the agenda + - Complementary material, not required but useful + </section> </section> <!-- Concepts --> @@ -111,8 +121,16 @@ data-charset="iso-8859-15"> </section> - <!-- Why use CI --> - <section data-markdown="content/what_git.md" + <!-- GitLab ci yml file --> + <section data-markdown="content/gitlab-ci-yml.md" + data-separator="^\n\n\n" + data-separator-vertical="^----------" + data-separator-notes="^Note:" + data-charset="iso-8859-15"> + </section> + + <!-- Runners--> + <section data-markdown="content/runners.md" data-separator="^\n\n\n" data-separator-vertical="^----------" data-separator-notes="^Note:" @@ -130,6 +148,15 @@ they have none at the moment </section> + <!-- Docker --> + <section data-markdown="content/docker.md" + data-separator="^\n\n\n" + data-separator-vertical="^----------" + data-separator-notes="^Note:" + data-charset="iso-8859-15" + id="docker"> + </section> + </div> </div> -- GitLab