Skip to content
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

Migrate builds from Travis to Github Actions #839

Merged
merged 1 commit into from
Nov 17, 2020

Conversation

utsavanand2
Copy link
Contributor

@utsavanand2 utsavanand2 commented Nov 6, 2020

Fixes #838

Issue #1585 for ref

Thanks to Lucas Roesler for his PR for buildx support #836
Signed-off-by: Utsav Anand [email protected]

Description

Motivation and Context

  • I have raised an issue to propose this change (required)

How Has This Been Tested?

Check out the ci-only build
and the publish build

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

with:
fetch-depth: 1
-
name: Get tags
Copy link
Member

Choose a reason for hiding this comment

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

IMHO The tag isn't required for builds / ci.

name: Local docker build (root image)
uses: docker/build-push-action@v2
with:
context: .
Copy link
Member

Choose a reason for hiding this comment

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

Context + path can be dropped.

Copy link
Member

Choose a reason for hiding this comment

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

Isn't there a new Dockerfile for this like Dockerfile.nonroot?

OK you are controlling it via --target release here -> https://github.com/openfaas/faas-cli/blob/master/build.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexellis I'm controlling it with

with:
   context: .
   file: ./Dockerfile
   target: release

and

with:
   context: .
   file: ./Dockerfile
   target: root

uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
Copy link
Member

Choose a reason for hiding this comment

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

Does one of the file: ./Dockerfile options need to be the root/non-root Dockerfile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can target just the non-root or the root docker image in CI, I just kept it here to be consistent with what we had in travis.yml

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_paths: '["./faas-cli*"]'
Copy link
Member

Choose a reason for hiding this comment

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

I would put the binaries into ./bin/

@alexellis
Copy link
Member

Closes #838 from @LucasRoesler

- "*"
pull_request:
branches:
- "master"
Copy link
Member

Choose a reason for hiding this comment

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

Should this be on * also?

runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@master
Copy link
Member

Choose a reason for hiding this comment

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

See the setup go action from openfaas/faas-netes#698

@utsavanand2 utsavanand2 force-pushed the github-actions branch 5 times, most recently from 72ce897 to 3e2d7e9 Compare November 8, 2020 08:25
@utsavanand2
Copy link
Contributor Author

@alexellis I've resolved the above issues. Does this look like ready to be merged?

@utsavanand2 utsavanand2 force-pushed the github-actions branch 7 times, most recently from 1074f36 to 87f9b74 Compare November 11, 2020 20:03
@derek
Copy link

derek bot commented Nov 15, 2020

Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off. That's something we need before your Pull Request can be merged. Please see our contributing guide.
Tip: if you only have one commit so far then run: git commit --amend --signoff and then git push --force.

@derek derek bot added the no-dco label Nov 15, 2020
@utsavanand2 utsavanand2 force-pushed the github-actions branch 3 times, most recently from b6b293f to 29f69fb Compare November 15, 2020 17:14
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
Copy link
Member

Choose a reason for hiding this comment

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

why can't we use the default ${{ secrets.GITHUB_TOKEN }} i feel like we discussed it in the wednesday call, but I can't remember why

Copy link
Contributor Author

@utsavanand2 utsavanand2 Nov 15, 2020

Choose a reason for hiding this comment

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

For the record: me and Lucas tried it and later found out it doesn't work for forked repos.
https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token

Copy link
Member

Choose a reason for hiding this comment

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

So what is CR_PAT?

Copy link
Member

Choose a reason for hiding this comment

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

If it's not convention then can we use DOCKER_PASSWORD as per all the other merged and released builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its a secret for Container Registry.
I have seen CR_PAT in the Github Docs, thought it would be better if we go with it. What do you think?
https://docs.github.com/en/free-pro-team@latest/packages/getting-started-with-github-container-registry/migrating-to-github-container-registry-for-docker-images#authenticating-with-the-container-registry

Copy link
Member

Choose a reason for hiding this comment

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

How faas-netes worked https://github.com/openfaas/faas-netes/tree/master/.github/workflows

is CR_PAT something that works without me doing something on each repo?

Copy link
Member

Choose a reason for hiding this comment

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

That link doesn't reference CR_PAT, is it the right link?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry I can see where CR_PAT is mentioned now. It's not a special variable and has no meaning to Github Actions - can you change to DOCKER_PASSWORD please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

REPO=${{ steps.get_repo_name.outputs.REPOSITORY_NAME }}
push: true
tags: |
ghcr.io/${{ steps.get_owner_name.outputs.OWNER_NAME }}/${{ steps.get_repo_name.outputs.REPOSITORY_NAME }}:${{ github.sha }}
Copy link
Member

Choose a reason for hiding this comment

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

I'm seeing a lot of duplication. Seems like this could be put into a similar variable and used again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean something like an ENV VAR?

Copy link
Member

Choose a reason for hiding this comment

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

The same way you split the string in a step, construct the GHCR main image prefix once instead of 6+ times.

Dockerfile Outdated
ARG NS
ARG REPO

LABEL org.opencontainers.image.source https://github.com/$NS/$REPO
Copy link
Member

Choose a reason for hiding this comment

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

Does that string need to be split out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it doesn't need to be split out. I'll put a = in between.

Copy link
Member

Choose a reason for hiding this comment

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

Can we not inject the complete URL instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you mean injecting the whole org.opencontainers.image.source=https://github.com/$REPO into the Dockerfile with build args, then I think it's not possible. The Dockerfile expects two args in LABEL, I get a red squiggly line saying so.
Screenshot 2020-11-17 at 1 54 01 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I get it, by URL you mean this> #839 (comment)

build-args: |
VERSION=latest-dev
GIT_COMMIT=${{ github.sha }}
NS=openfaas
Copy link
Member

Choose a reason for hiding this comment

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

Can't this be a single variable of GITHUB_REPOSITORY?

Copy link
Member

Choose a reason for hiding this comment

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

Or whatever is the full path to the repo to inject in the special label?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we can get the GITHUB_URL into the build args. Sure!

build-args: |
VERSION=latest-dev
GIT_COMMIT=${{ github.sha }}
NS=openfaas
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot!

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

Changed requested please. What do you say to aiming to have everything ready for a merge on Weds?

@utsavanand2 utsavanand2 force-pushed the github-actions branch 3 times, most recently from eebbaa9 to bc88dc9 Compare November 17, 2020 08:53
Fixes openfaas#838

Thanks to Lucas Roesler for his PR for buildx support openfaas#836
Signed-off-by: Utsav Anand <[email protected]>
Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

Your IMAGE_PREFIX is much easier to follow than the duplicated strings. Thank you for working on this.

name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Local docker build (non-root image)
Copy link
Member

Choose a reason for hiding this comment

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

Do this in a follow-up PR if you want, but we need to do a multi-arch build upon every commit, not just upon a release tag. This found issues in the past.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try to put up a PR by tonight to address this 👆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexellis I've resolved it in a PR I've just put up
#843

@alexellis alexellis merged commit 15cc71a into openfaas:master Nov 17, 2020
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.

Migrate from Travis to Github Actions
3 participants