From 990baea47c2a559e6f71f8d16435490db1c5b808 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 21 Aug 2024 09:36:15 -0600 Subject: [PATCH 1/8] Added container building working --- .github/workflows/build-container.yml | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/build-container.yml diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml new file mode 100644 index 0000000..2fad61e --- /dev/null +++ b/.github/workflows/build-container.yml @@ -0,0 +1,48 @@ +name: build and publish containers +on: + workflow_dispatch: + push: + tags: + - v* +permissions: + packages: write + contents: read +jobs: + build-magellan: + runs-on: ubuntu-latest + steps: + - name: check out the repo + uses: actions/checkout@v4 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + # list of Docker images to use as base name for tags + images: | + ghcr.io/openchami/magellan + + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + type=sha + - name: setup Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to github container repo + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push magellan + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64 + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file From a1b26e68ae6e25970235db87a2227cda5576e03b Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 21 Aug 2024 10:09:21 -0600 Subject: [PATCH 2/8] Fixed automatic builds with docker container --- .github/workflows/build-container.yml | 48 --------------------------- .github/workflows/main.yml | 8 +++-- .goreleaser.yaml | 18 ++++++++++ 3 files changed, 24 insertions(+), 50 deletions(-) delete mode 100644 .github/workflows/build-container.yml diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml deleted file mode 100644 index 2fad61e..0000000 --- a/.github/workflows/build-container.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: build and publish containers -on: - workflow_dispatch: - push: - tags: - - v* -permissions: - packages: write - contents: read -jobs: - build-magellan: - runs-on: ubuntu-latest - steps: - - name: check out the repo - uses: actions/checkout@v4 - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - # list of Docker images to use as base name for tags - images: | - ghcr.io/openchami/magellan - - # generate Docker tags based on the following events/attributes - tags: | - type=schedule - type=ref,event=branch - type=ref,event=pr - type=semver,pattern=v{{version}} - type=semver,pattern=v{{major}}.{{minor}} - type=semver,pattern=v{{major}} - type=sha - - name: setup Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to github container repo - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push magellan - uses: docker/build-push-action@v5 - with: - platforms: linux/amd64 - context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 97aaf48..22349aa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,8 +11,6 @@ permissions: write-all # Necessary for the generate-build-provenance action with jobs: build: - - runs-on: ubuntu-latest steps: @@ -20,6 +18,12 @@ jobs: uses: actions/setup-go@v5 with: go-version: 1.21 + - name: Docker Login + uses: docker/login-action@v3 + with: + registry :ghcr.io + username: ${{ gihub.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Checkout uses: actions/checkout@v4 with: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 7e7b51d..4ce72ea 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -25,6 +25,24 @@ archives: - CHANGELOG.md - README.md - bin/magellan.sh +dockers: + - + image_templates: + - ghcr.io/openchami/{{.ProjectName}}:latest + - ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }} + - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }} + - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }} + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + extra_files: + - LICENSE + - CHANGELOG.md + - README.md + - bin/magellan.sh checksum: name_template: 'checksums.txt' snapshot: From ad52bf9930557921e338e0d8de95918e101bc2bb Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 21 Aug 2024 10:13:42 -0600 Subject: [PATCH 3/8] Fixed typo in workflow --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 22349aa..7f60826 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: - name: Docker Login uses: docker/login-action@v3 with: - registry :ghcr.io + registry: ghcr.io username: ${{ gihub.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Checkout From 054fc58e1a58e81cf835162bf8a8e0d523ae49bb Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 21 Aug 2024 10:15:47 -0600 Subject: [PATCH 4/8] Fixed typo in workflow --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7f60826..5227ed9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: uses: docker/login-action@v3 with: registry: ghcr.io - username: ${{ gihub.actor }} + username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Checkout uses: actions/checkout@v4 From 71256f6154b5cdb40c32a0d51302d252884622f5 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 21 Aug 2024 10:56:41 -0600 Subject: [PATCH 5/8] Fixed deprecation warning in goreleaser --- .goreleaser.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 4ce72ea..ed4d7dc 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -46,7 +46,7 @@ dockers: checksum: name_template: 'checksums.txt' snapshot: - name_template: "{{ incpatch .Version }}-next" + version_template: "{{ incpatch .Version }}-next" changelog: sort: asc filters: From b1beac052d721247fb569e714b476a0f3d6d2c07 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 21 Aug 2024 11:17:22 -0600 Subject: [PATCH 6/8] Fixed permissions in workflow --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5227ed9..2629cfd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,7 +6,7 @@ on: tags: - v* -permissions: write-all # Necessary for the generate-build-provenance action with containers +permissions: write-all jobs: From 327eb35f4a38ed72ebbf726e5c2a3d77176b4104 Mon Sep 17 00:00:00 2001 From: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:36:15 -0600 Subject: [PATCH 7/8] release: prefix all version tags with "v" The goreleaser `.Tag` template already uses the format `vX.Y.Z`, so that's fine. But our custom `.Major` and `.Major.Minor` formats don't include that `v` prefix, so we need to add it manually. --- .goreleaser.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index ed4d7dc..ceee709 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -30,8 +30,8 @@ dockers: image_templates: - ghcr.io/openchami/{{.ProjectName}}:latest - ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }} - - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }} - - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }} + - ghcr.io/openchami/{{.ProjectName}}:v{{ .Major }} + - ghcr.io/openchami/{{.ProjectName}}:v{{ .Major }}.{{ .Minor }} build_flag_templates: - "--pull" - "--label=org.opencontainers.image.created={{.Date}}" From f393a2ab7f99b76f2ab73ae769251ba569ec7059 Mon Sep 17 00:00:00 2001 From: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:23:54 -0600 Subject: [PATCH 8/8] magellan.sh: remove unused build helper function We compile as part of the Docker build process, so an extra helper isn't really needed. --- bin/magellan.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bin/magellan.sh b/bin/magellan.sh index 98b3a37..c91d922 100755 --- a/bin/magellan.sh +++ b/bin/magellan.sh @@ -15,10 +15,6 @@ SCAN_PARAMS="" COLLECT_PARAMS="" -function build(){ - go mod tidy && go build -C bin/magellan -} - function scan() { # ./magellan scan --subnet 172.16.0.0 --port 443 ${EXE} scan ${SCAN_PARAMS} @@ -30,7 +26,7 @@ function scan() { function list(){ # ./magellan list - ${EXE} list + ${EXE} list } function collect() { @@ -48,7 +44,7 @@ function collect() { # parse incoming arguments to set variables while [[ $# -gt 0 ]]; do - case $1 in + case $1 in --scan) SCAN_PARAMS="$2" shift @@ -107,7 +103,7 @@ while [[ $# -gt 0 ]]; do ARGS+=("$1") # save positional arg shift # past argument ;; - esac + esac done set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters