Today I Learned

6 posts by łukaszpawlik

Persisting files between jobs in CircleCI's worklow

When you have a file or files that you want to persist between jobs in Workflow you can add the step persist_to_workspace in the job that creates the files.

For example:

Assuming that you have a job that builds JS project and creates a zip under builds/ in the workdir directory you can add step:

      - persist_to_workspace:
          root: .
          paths:
            - builds/*

And in the followup jobs you need to call

      - attach_workspace:
          at: ./

to have access to those files. The files will be accessible under ./builds directory.

Docs:

https://circleci.com/docs/2.0/configuration-reference/#persist_to_workspace https://circleci.com/docs/2.0/configuration-reference/#attach_workspace

Use templatefile function instead of template_file

Since terraform v 0.12 it’s recommended to use templatefile(path, vars) function instead of data source template_file.

As data source provider has it’s own copy of template file engine that is separate from the Terraform itself. The engine depends on the version of Terraform that the provider was compiled with and not the one run on your system.

Using templatefile(path, vars) function will give you more consistent results as it depends on the version of Terraform you are using.

Example usage:

templatefile("${path.module}/backends.tmpl", { port = 8080, ip_addrs = ["10.0.0.1", "10.0.0.2"] })

Source:

https://www.terraform.io/docs/configuration/functions/templatefile.html https://www.terraform.io/docs/providers/template/d/file.html

Get key's value from Vault secret with multiple keys

Let’s assume that you have defined a secret in vault with multiple key’s defined:

➜ vault kv get secret/example
====== Metadata ======
Key              Value
---              -----
created_time     2020-03-12T12:25:24.912324854Z
deletion_time    n/a
destroyed        false
version          3

==== Data ====
Key      Value
---      -----
test     test1234
test2    dawdawaw

You can retrieve value from a specific key with a flag -field=key_name. For example:

➜ vault kv get -field=test2 secret/example
dawdawaw

How to make path accessible in Rails Engine

Since routes in engine are isolated by default from main application so that you can have the same routes without clashing using default route helpers like about_path from main app will result in an error when you try to load it from inside the engine or access engine root from main app.

To fix that issue assuming you have an engine mounted:

Blorgh::Engine.routes.draw do
  resources :articles
end

to enforce using engine roots you need to change about_path to blorgh.about_path and to enforce using main application routes you need to change it to main_app.about_path