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

Workflow for main branch that publishes plugin to ghcr.io #80

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: PR Check
Copy link
Member

Choose a reason for hiding this comment

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

This should be renamed.


on:
push:
branches:
- "main"

jobs:
build:
name: Build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Check out code
uses: actions/checkout@v3

- name: generate-tag
Copy link
Member

Choose a reason for hiding this comment

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

Rather than generating a tag, we could use edge for tracking main. That's how other projects in the OPA or does it.

It would be good if the this flow worked when an actual tag was pushed too, and used that if found.

Copy link
Contributor Author

@larhauga larhauga Nov 20, 2023

Choose a reason for hiding this comment

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

What do you mean by using edge here? Are there any good examples in the other projects here?
I can rewrite it to only trigger on tag pushes if that is your preferred way? Like https://github.com/open-policy-agent/opa-envoy-plugin/blob/main/.github/workflows/post-tag.yaml?

Edit: updated the branch with push on tag :)

Copy link
Member

Choose a reason for hiding this comment

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

Yep! Or https://github.com/open-policy-agent/opa/blob/main/.github/workflows/post-merge.yaml#L139

I.e. use the tag edge for tracking what's currently the top of the main branch. That workflow should run on all pushes to main. Then, ideally we'd have another similar workflow that runs only on pushed tags, and which uses the tag for... well, tagging :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, If I understood you correctly, the PR should be updated with two workflows. Does it look OK to you?
Happy to help getting this the way you want 👍

run: |
echo "TAG=$(git show -s --date=format:'%Y%m%d-%H%M' --format=%cd)" >> $GITHUB_ENV

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and publish docker plugin
env:
REPO: ghcr.io/${{ github.repository }}
VERSION: ${{ env.TAG }}
run: |
make plugin
docker plugin push "$REPO:$VERSION"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
VERSION ?= 0.8
GO_VERSION := 1.19.1
GOLANGCI_LINT_VERSION := v1.49.0
REPO := openpolicyagent/opa-docker-authz
REPO := openpolicyagent/opa-docker-authz-v2

all: build

Expand Down
6 changes: 3 additions & 3 deletions plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ docker image build -t rootfsimage .
id=`docker container create rootfsimage true`
docker container export "$id" | tar -x -C ./rootfs

echo "Creating plugin "${REPO}-v2:${VERSION}" ..."
docker plugin create "${REPO}-v2:${VERSION}" .
echo "Creating plugin "${REPO}:${VERSION}" ..."
docker plugin create "${REPO}:${VERSION}" .

echo "Cleanup..."
docker container rm -f "$id" > /dev/null
docker image rm -f rootfsimage > /dev/null
rm -rf ./rootfs
rm -rf ./rootfs