From 02fd66cd9ddd93bab0a144c7441a20359b390cb0 Mon Sep 17 00:00:00 2001 From: Mischa van den Burg Date: Tue, 30 Apr 2024 18:30:00 +0200 Subject: [PATCH] Automated commit at Tue Apr 30 18:30:00 CEST 2024 --- ...ersioning using GitHub Actions - index.md} | 6 ++ content/GitHub.md | 2 +- ...s for GitHub Actions to create packages.md | 35 ++++++++++++ ...ices in GitHub Actions for looping jobs.md | 55 +++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) rename content/{Building multiple Docker images using automatic versioning using GitHub Actions.md => Building multiple Docker images using automatic versioning using GitHub Actions - index.md} (66%) create mode 100644 content/Managing permissions for GitHub Actions to create packages.md create mode 100644 content/Using matrix - matrices in GitHub Actions for looping jobs.md diff --git a/content/Building multiple Docker images using automatic versioning using GitHub Actions.md b/content/Building multiple Docker images using automatic versioning using GitHub Actions - index.md similarity index 66% rename from content/Building multiple Docker images using automatic versioning using GitHub Actions.md rename to content/Building multiple Docker images using automatic versioning using GitHub Actions - index.md index 40d716692..be777c4d9 100644 --- a/content/Building multiple Docker images using automatic versioning using GitHub Actions.md +++ b/content/Building multiple Docker images using automatic versioning using GitHub Actions - index.md @@ -1,6 +1,12 @@ +[[Creating tags based on conventional commits with github actions]] + +[[Managing permissions for GitHub Actions to create packages]] + [[Using matrix - matrices in GitHub Actions for looping jobs]] + + ## Links: diff --git a/content/GitHub.md b/content/GitHub.md index 8239d93ce..323c46d23 100644 --- a/content/GitHub.md +++ b/content/GitHub.md @@ -1,5 +1,5 @@ Actions -- [[Building multiple Docker images using automatic versioning using GitHub Actions]] +- [[Building multiple Docker images using automatic versioning using GitHub Actions - index]] ## Links: diff --git a/content/Managing permissions for GitHub Actions to create packages.md b/content/Managing permissions for GitHub Actions to create packages.md new file mode 100644 index 000000000..9c4c5c138 --- /dev/null +++ b/content/Managing permissions for GitHub Actions to create packages.md @@ -0,0 +1,35 @@ +- On the main page of your organization, go to Packages +- Go to the package and open "Package settings" in the right sidebar +- Under Manage Actions access, add the repo as the source +- Make sure to allow Write acces + +![[Pasted image 20240429145500.png]] + +In the source repo, where the GitHub Actions Workflow is running, go to settings, actions, select the workflow, and add write permission there too. + +![[Pasted image 20240429151841.png]] + +Finally, we also need to add permissions in the workflow yaml: + +```yaml +build_and_push: + name: Build image & push + runs-on: ubuntu-latest + permissions: + contents: read + packages: write +``` + +See also: + +[github actions - ERROR: denied: installation not allowed to Create organization package - Stack Overflow](https://stackoverflow.com/questions/76607955/error-denied-installation-not-allowed-to-create-organization-package) + +[denied: installation not allowed to Create organization package · Issue #606 · docker/build-push-action (github.com)](https://github.com/docker/build-push-action/issues/606) + + + +## Links: + + + +202404301753 \ No newline at end of file diff --git a/content/Using matrix - matrices in GitHub Actions for looping jobs.md b/content/Using matrix - matrices in GitHub Actions for looping jobs.md new file mode 100644 index 000000000..b8fb0a9e0 --- /dev/null +++ b/content/Using matrix - matrices in GitHub Actions for looping jobs.md @@ -0,0 +1,55 @@ +One of the problems I needed to solve was that I needed build multiple images, but I didn't want to have a code block for each. After some research I found a way to loop over multiple values in GitHub Actions using matrices. + +In the example below, I set three variables in the matrix and each of these are called in the Build and push step. + +```yaml + build_and_push: + permissions: + contents: write + packages: write + + runs-on: ubuntu-latest + + strategy: + matrix: + include: + - image: ghcr.io/ssi-dk/sap-web + dockerfile: app/Dockerfile + path: app + - image: ghcr.io/ssi-dk/sap-api + dockerfile: web/Dockerfile + path: web + - image: ghcr.io/ssi-dk/bifrost-queue-broker + dockerfile: bifrost/bifrost_queue_broker/Dockerfile + path: bifrost/bifrost_queue_broker + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # loops over all images in the matrix defined on top + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: ${{ matrix.path }} + platforms: linux/amd64 + tags: ${{ matrix.image }}:${{ needs.prepare_tag.outputs.tag }} + file: ${{ matrix.dockerfile }} + push: true + +``` + + +## Links: + +[Using a matrix for your jobs - GitHub Docs](https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs) + +202404291839 \ No newline at end of file