Skip to content

Persist the old preview URLs for future jobs #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ChristianRimondi
Copy link
Member

@ChristianRimondi ChristianRimondi commented Mar 29, 2019

This uses the labels added in #4 to generate and persist a json file with a list of previews info associated with the containers removed during the current orb execution. The file format is something like:

{
  "PR_NUMBER": {
     "preview_url": "https://SUBDOMAIN.DOMAIN",
     "branch": "BRANCH"
  }
}

This adopts the same approach used in #3, so the way of retrieving the persisted file is the same:

  steps:
    - attach_workspace:
        # Must be absolute path or relative path from working_directory
        at: /tmp/workspace

    - run: |
        cat /tmp/workspace/deleted-previews.json

To generate the json file it uses docker inspect to retrieve the containers info in a json format and jq to parse this info:

# This selects only the containers with a label named `pull-request`
map(select(.Config.Labels["pull-request"]))

# This maps the container info returned by `docker inspect` into an array of
# `{"key": "PR_NUMBER", "value": {"branch": "BRANCH", "preview_url": "PREVIEW_URL"}}`
map({
  key: .Config.Labels["pull-request"],
  value: {
    branch: .Config.Labels["branch"],
    preview_url: "https://\(.Config.Labels["subdomain"]).<< parameters.domain >>"
  }
})

# Convert an array `[{"key": k, "value": v}]` into an object `{k: v}`
from_entries

@ChristianRimondi ChristianRimondi self-assigned this Mar 29, 2019
@ChristianRimondi ChristianRimondi force-pushed the christianr/add-metadata-to-containers branch from 7317ef1 to 4c4ba82 Compare March 29, 2019 15:45
@ChristianRimondi ChristianRimondi force-pushed the christianr/persist-old-preview-urls branch from c094340 to 6c66649 Compare March 29, 2019 15:58
@ChristianRimondi ChristianRimondi changed the title [WIP] Persist the old preview URLs for future jobs Persist the old preview URLs for future jobs Mar 29, 2019
@ChristianRimondi ChristianRimondi force-pushed the christianr/add-metadata-to-containers branch 3 times, most recently from 38bc819 to d978141 Compare April 1, 2019 11:06
@ChristianRimondi ChristianRimondi force-pushed the christianr/persist-old-preview-urls branch from 6c66649 to ba2e049 Compare April 1, 2019 14:14
@ChristianRimondi ChristianRimondi force-pushed the christianr/add-metadata-to-containers branch from d978141 to fffc5d8 Compare April 1, 2019 14:39
@ChristianRimondi ChristianRimondi changed the base branch from christianr/add-metadata-to-containers to master April 1, 2019 15:10
This uses the labels added in #4 to generate and persist a json file
with a list of previews info associated with the containers removed
during the current orb execution. The file format is something like:

```
{
  "PR_NUMBER": {
     "preview_url": "https://SUBDOMAIN.DOMAIN",
     "branch": "BRANCH"
  }
}
```

This adopts the same approach used in #3, so the way of retrieving the
persisted file is the same:

```
  steps:
    - attach_workspace:
        # Must be absolute path or relative path from working_directory
        at: /tmp/workspace

    - run: |
        cat /tmp/workspace/deleted-previews.json
```

To generate the json file it uses `docker inspect` to retrieve the
containers info in a json format and `jq` to parse this info:

```
  # This selects only the containers with a label named `pull-request`
  map(select(.Config.Labels["pull-request"]))

  # This maps the container info returned by `docker inspect` into an array of
  # `{"key": "PR_NUMBER", "value": {"branch": "BRANCH", "preview_url": "PREVIEW_URL"}}`
  map({
    key: .Config.Labels["pull-request"],
    value: {
      branch: .Config.Labels["branch"],
      preview_url: "https://\(.Config.Labels["subdomain"]).<< parameters.domain >>"
    }
  })

  # Convert an array `[{"key": k, "value": v}]` into an object `{k: v}`
  from_entries
```
@ChristianRimondi ChristianRimondi force-pushed the christianr/persist-old-preview-urls branch from ba2e049 to 79d607e Compare April 2, 2019 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant