Skip to content

ci: use github action for automated deployment - #1337

Merged
nschonni merged 2 commits into
nodejs:masterfrom
ttshivers:github_pr
Oct 7, 2020
Merged

nschonni merged 2 commits into
nodejs:masterfrom
ttshivers:github_pr

Conversation

@ttshivers

@ttshivers ttshivers commented Sep 23, 2020 •

Copy link
Copy Markdown
Member

This replaces the Travis ci automated deployment with a GitHub action.

Requires the use of some bot token to make a commits at nodejs-github-bot/official-images and then open PRs on docker-library/official-images .

Refs: #1312

Comment thread .github/prFormat.js Resolved
@nschonni

nschonni commented Sep 24, 2020 •

Copy link
Copy Markdown
Member

Cool, beat me to it. Here is what I was working on locally, because there are probably some bits you might want

name: PR to official images

on:
  pull_request_target:
    types:
      - closed
    paths:
      - "**/Dockerfile"
      - "**/architectures"
      - "**/docker-entrypoint.sh"
      - "generate-stackbrew-library.sh"
      - "functions.sh"

jobs:
  pr:
    runs-on: ubuntu-latest
    if: github.repository_owner == 'nodejs' && github.event.pull_request.merged_by != ''

    steps:
      - name: Checkout the docker-node repo
        uses: actions/checkout@v2
        with:
          path: docker-node
          fetch-depth: 50

      - name: Checkout the docker-library/official-images repo
        uses: actions/checkout@v2
        with:
          path: official-images
          repository: docker-library/official-images

      - name: Generate Stackbrew for diff
        run: |
          cd docker-node
          ./generate-stackbrew-library.sh > ../official-images/library/node

      - uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.GITHUB_API_TOKEN }}
          push-to-fork: nodejs-github-bot/official-images
          title: "Node: ${{ github.event.pull_request.title}}"
          path: official-images
          commit-message: "Pull Request: {{ github.event.pull_request.html_url }}"

@ttshivers

Copy link
Copy Markdown
Member Author

I have extra complexity in mine that handles if commits are pushed to master without going through a pull request. Should I assume that won't happen and take out some of that stuff?

@nschonni nschonni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few of the things you're grabbing through scripts are available in the github.event.pull_request object.
That's available in the pull_request_target version, and has the benifit of the built in repo token working for the comment part (but not the PR/push)

Comment thread .github/workflows/auto_pr.yml Resolved
Comment thread .github/workflows/auto_pr.yml Resolved
@nschonni

Copy link
Copy Markdown
Member

The main branch is protected, so it can only be changed through PRs. That should simplify some stuff for you 😄

@ttshivers
ttshivers force-pushed the github_pr branch 2 times, most recently from 5088de3 to 1629201 Compare September 24, 2020 01:18
@ttshivers

Copy link
Copy Markdown
Member Author

@nschonni I see in your approach, you are using the pull_request_target trigger. It seems like it does have some benefits in that you have access to the PR without having to search for it. I changed over to that method and added the other differences too.

@ttshivers
ttshivers force-pushed the github_pr branch 4 times, most recently from 3ff6a1b to 043bd04 Compare September 24, 2020 01:42

@nschonni nschonni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

Comment thread .github/workflows/official-pr.yml Resolved
Comment thread .github/workflows/official-pr.yml Resolved
Comment thread .github/workflows/official-pr.yml Resolved
@nschonni
nschonni requested a review from a team September 24, 2020 01:55
@nschonni

Copy link
Copy Markdown
Member

@nodejs/docker (or maybe specifically @LaurentGoderre) does anyone have the token that we used for Travis that they could put in the GitHub secrets section?

@SimenB SimenB left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes me very happy 😀 Perfect #1337 👍

@SimenB

SimenB commented Sep 24, 2020

Copy link
Copy Markdown
Member

@nodejs/build-infra could you add the bot's token to the repo's secrets? Or is that stuff managed by some other group?

Comment thread .github/workflows/official-pr.yml Outdated
./generate-stackbrew-library.sh > ../official-images/library/node

- name: Create PR in official-images
id: cpr

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

full name instead of some abbreviation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How's create-pr

@nschonni

Copy link
Copy Markdown
Member

Created nodejs/admin#556 since it seems like there is more of an official process now around the tokens and secrets

@rvagg

rvagg commented Sep 25, 2020

Copy link
Copy Markdown
Member

docker_node_github_api_token.md is in build/github-bot in the secrets repo already, I assume that's what you're asking for?

@nschonni

Copy link
Copy Markdown
Member

@rvagg yup, that would work! We're just looking to switch the CI the PR setup is running on

@mmarchini

Copy link
Copy Markdown

Still need approval on the admin repo. I can setup the secrets on this repo when request is approved.

Comment thread .github/workflows/official-pr.yml Resolved
Comment thread .github/workflows/official-pr.yml Resolved
@SimenB

SimenB commented Sep 27, 2020

Copy link
Copy Markdown
Member

One more question, is it possible to not run this if tests or building an image fail? Or is the thinking that since this only runs on master (which is protected), CI was green before merging so we don't need to wait.

Looking at https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idneeds it doesn't seem like the ID is referencable across workflows. And we wouldn't know which to wait for either as builds are triggered conditionally. I guess we could try to have one workflow instead of many? Not sure how that would look

@mmarchini

Copy link
Copy Markdown

The deployment steps would need to be on the same job as the tests so if a test fails this job doesn't run, or the job has to be in the same file and can depend on the test/build job.

@ttshivers

Copy link
Copy Markdown
Member Author

The deployment steps would need to be on the same job as the tests so if a test fails this job doesn't run, or the job has to be in the same file and can depend on the test/build job.

I like this way too. Another way is to use some an action like lewagon/wait-on-check-action to wait for a test workflow to finish before allowing another one to run.

@nschonni

Copy link
Copy Markdown
Member

@rvagg we got the thumbs up over on the admin repo nodejs/admin#556 (comment) if you have access to set the secret

@rvagg

rvagg commented Sep 30, 2020

Copy link
Copy Markdown
Member

no, I don't think I have all the required access, @mmarchini might be the best person for this?

@nschonni

nschonni commented Oct 2, 2020

Copy link
Copy Markdown
Member

From @yosifkit docker-library/official-images#8824 (comment)

I think we'd rather that the bot be improved to only open a single PR at a time.

Maybe we should drop the branch suffix and just keep a single "official-images" branch that it could keep pushing to the same PR till landed

Comment thread .github/workflows/official-pr.yml Resolved
This will have the action use a single branch and update or create a PR
@nschonni

nschonni commented Oct 6, 2020

Copy link
Copy Markdown
Member

I think we're good to land this, just wanted to walk through the flow now that we're re-using the branch

Flow 1:

  1. PR A lands here
  2. Action creates upstream PR ##
  3. Action comments on PR A
  4. Upstream PR lands. Branch is leftover or deleted?

Flow 2:

  1. PR A lands here
  2. Action creates upstream PR ##
  3. Action comments on PR A
  4. PR B lands here
  5. Action pushes new commits. Title stays the same?
  6. Action comments on PR B
  7. Upstream PR lands. Branch is leftover or deleted?

Flow 3:

  1. PR A lands here
  2. Action creates upstream PR ##
  3. Action comments on PR A
  4. Upstream PR is rejected/closed. Branch is leftover or deleted?

@ttshivers

Copy link
Copy Markdown
Member Author

The action uses peter-evans/create-pull-request, and they describe their behavior like: https://github.com/peter-evans/create-pull-request#action-behaviour.

In Flow 1, currently the branch is NOT deleted because delete-branch is not specified and defaults to false. This can be changed if you want.

In Flow 2, step 5, the PR title will be updated (so will the PR body). Step 7, branch is currently not deleted because of what I mentioned above.

In Flow 3, branch is not deleted for same reason.

I think it may be a good idea to set delete-branch to true because it will cause the branch to be deleted in all 3 flows, which seems desirable.

@nschonni

nschonni commented Oct 7, 2020

Copy link
Copy Markdown
Member

I can't tell from the docs if there would need to be some sort of repository_dispatch setup on the other side for the delete branch to work, so I'm good leaving it for now.
I think there maybe be an issue with the fact we're using the base action/checkout then using the PR action to re-use/update the branch, but unless anyone has any last minute changes, I think we should land this and then test it out by landing #1347 then #1348

@ttshivers

ttshivers commented Oct 7, 2020 •

Copy link
Copy Markdown
Member Author

I can't tell from the docs if there would need to be some sort of repository_dispatch setup on the other side for the delete branch to work, so I'm good leaving it for now.
I think there maybe be an issue with the fact we're using the base action/checkout then using the PR action to re-use/update the branch, but unless anyone has any last minute changes, I think we should land this and then test it out by landing #1347 then #1348

If delete-branch is true, it appears that the action would delete the branch the next time it is invoked on this repository (and there is no diff). https://github.com/peter-evans/create-pull-request/blob/e17bb55cb71e482dbeb01f204bff23f21dd20c77/src/create-pull-request.ts#L204

Overall, I now agree with you and we probably don't need to enable it.

As for wondering if there could be conflicts, it pushes to the branch with this command: https://github.com/peter-evans/create-pull-request/blob/e17bb55cb71e482dbeb01f204bff23f21dd20c77/src/create-pull-request.ts#L179

await git.push([
  '--force-with-lease',
  branchRemoteName,
  `HEAD:refs/heads/${inputs.branch}`
])

@nschonni

nschonni commented Oct 7, 2020

Copy link
Copy Markdown
Member

OK, I'm going to land this and the other 2 and we'll see how it goes!
Thanks for all the work

@nschonni
nschonni merged commit 85032ae into nodejs:master Oct 7, 2020
@nschonni

nschonni commented Oct 7, 2020

Copy link
Copy Markdown
Member

@mmarchini FYI, we did run into the merge issue with the first PR using the pull_request_target, so I guess the regular merge isn't the workaround and we'd need to switch the strategy to rebase merge

@ttshivers

Copy link
Copy Markdown
Member Author

@mmarchini FYI, we did run into the merge issue with the first PR using the pull_request_target, so I guess the regular merge isn't the workaround and we'd need to switch the strategy to rebase merge

Yeah I messed up in my initial testing of the trigger. When I run the tests again, its behaving the same way it's behaving in this repo now.

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.

6 participants