Skip to content

Commit 1c58803

Browse files
committed
add optimization level arg
1 parent 42ffd8c commit 1c58803

File tree

8 files changed

+69
-53
lines changed

8 files changed

+69
-53
lines changed

.goreleaser-pre.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ before:
1515

1616
builds:
1717
# https://goreleaser.com/customization/build/
18-
- id: build
18+
- id: policy
1919
main: ./cmd/policy
2020
binary: policy
2121
goos:
@@ -40,9 +40,10 @@ builds:
4040

4141
archives:
4242
# https://goreleaser.com/customization/archive/
43-
- format: zip
44-
builds:
45-
- build
43+
- format:
44+
- zip
45+
ids:
46+
- policy
4647
files:
4748
- LICENSE
4849
- README.md

.goreleaser.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ before:
1515

1616
builds:
1717
# https://goreleaser.com/customization/build/
18-
- id: build
18+
- id: policy
1919
main: ./cmd/policy
2020
binary: policy
2121
goos:
@@ -40,9 +40,10 @@ builds:
4040

4141
archives:
4242
# https://goreleaser.com/customization/archive/
43-
- format: zip
44-
builds:
45-
- build
43+
- formats:
44+
- zip
45+
ids:
46+
- policy
4647
files:
4748
- LICENSE
4849
- README.md

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/opcr-io/policy
22

33
go 1.24
44

5-
toolchain go1.24.5
5+
toolchain go1.24.6
66

77
require (
88
github.com/Masterminds/sprig v2.22.0+incompatible

go.work

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
go 1.24
22

3-
toolchain go1.24.5
3+
toolchain go1.24.6
44

55
use (
66
.

oci/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/opcr-io/policy/oci
22

33
go 1.23.0
44

5-
toolchain go1.24.5
5+
toolchain go1.24.6
66

77
require (
88
github.com/containerd/containerd v1.7.25

parser/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/opcr-io/policy/parser
22

33
go 1.23
44

5-
toolchain go1.24.5
5+
toolchain go1.24.6
66

77
require (
88
github.com/containerd/containerd v1.7.25

scripts/build.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/usr/bin/env bash
22

33
# set defaults when not set
4-
[ -z "${INPUT_REVISION}" ] && INPUT_REVISION=${GITHUB_SHA}
5-
[ -z "${INPUT_VERBOSITY}" ] && INPUT_VERBOSITY="error"
6-
[ -z "${INPUT_SOURCE_URL}" ] && INPUT_SOURCE_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
4+
[ -z "${INPUT_REVISION}" ] && INPUT_REVISION=${GITHUB_SHA}
5+
[ -z "${INPUT_VERBOSITY}" ] && INPUT_VERBOSITY="error"
6+
[ -z "${INPUT_SOURCE_URL}" ] && INPUT_SOURCE_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
77
[ -z "${INPUT_REGO_VERSION}"] && INPUT_REGO_VERSION="rego.v0"
8+
[ -z "${INPUT_OPTIMIZE}"] && INPUT_OPTIMIZE="disabled"
89

910
# validate if values are set
1011
[ -z "${INPUT_SRC}" ] && echo "INPUT_SRC is not set exiting" && exit 2
1112
[ -z "${INPUT_TAG}" ] && exit "INPUT_TAG is not set exiting" && exit 2
1213
[ -z "${INPUT_REVISION}" ] && exit "INPUT_REVISION is not set exiting" && exit 2
1314
[ -z "${INPUT_VERBOSITY}" ] && exit "INPUT_VERBOSITY is not set exiting" && exit 2
1415
[ -z "${INPUT_SOURCE_URL}" ] && exit "INPUT_SOURCE_URL is not set exiting" && exit 2
16+
[ -z "${INPUT_OPTIMIZE}" ] && exit "INPUT_OPTIMIZE is not set exiting" && exit 2
1517

1618
if [[ -z "${GITHUB_WORKSPACE}" ]]; then
1719
SRC_PATH=$PWD/$INPUT_SRC
@@ -42,6 +44,20 @@ case ${INPUT_VERBOSITY} in
4244
;;
4345
esac
4446

47+
OPTIMIZE=0
48+
case ${INPUT_OPTIMIZE} in
49+
"disabled")
50+
OPTIMIZE=0
51+
;;
52+
"recommended")
53+
OPTIMIZE=1
54+
;;
55+
"aggressive")
56+
OPTIMIZE=2
57+
;;
58+
esac
59+
60+
4561
# output all inputs env variables
4662
echo "POLICY-BUILD $(/app/policy version | sed 's/Policy CLI.//g')"
4763
printf "\n"
@@ -52,6 +68,7 @@ echo "INPUT_REVISION ${INPUT_REVISION}"
5268
echo "INPUT_VERBOSITY ${INPUT_VERBOSITY} (${VERBOSITY})"
5369
echo "INPUT_SOURCE_URL ${INPUT_SOURCE_URL}"
5470
echo "INPUT_REGO_VERSION ${INPUT_REGO_VERSION}"
71+
echo "INPUT_OPTIMIZE ${INPUT_OPTIMIZE} (${OPTIMIZE})"
5572
echo "SRC_PATH ${SRC_PATH}"
5673
printf "\n"
5774

@@ -61,7 +78,7 @@ printf "\n"
6178
e_code=0
6279

6380
# construct commandline arguments
64-
CMD="/app/policy build ${SRC_PATH} --tag ${INPUT_TAG} --rego-version=${INPUT_REGO_VERSION} --verbosity=${VERBOSITY} --annotations=org.opencontainers.image.source=${INPUT_SOURCE_URL}"
81+
CMD="/app/policy build ${SRC_PATH} --tag ${INPUT_TAG} --rego-version=${INPUT_REGO_VERSION} --verbosity=${VERBOSITY} --optimize=${OPTIMIZE} --annotations=org.opencontainers.image.source=${INPUT_SOURCE_URL}"
6582

6683
# execute command
6784
eval "$CMD" || e_code=1

templates/github/.github/workflows/build-release-policy.yaml.tmpl

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,40 @@ jobs:
1212
name: build
1313

1414
steps:
15-
- uses: actions/checkout@v3
15+
-
16+
uses: actions/checkout@v4
1617
with:
1718
fetch-depth: 0
18-
19-
- name: Read config
19+
-
20+
name: Read config
2021
id: config
21-
uses: opcr-io/ga-yaml-parser@v0.1
22+
uses: gertd/yaml-reader-action@v1
2223
with:
2324
file: .github/config.yaml
24-
25-
- name: List Sver Tags
26-
uses: aserto-dev/sver-action@v0
27-
id: "sver"
25+
-
26+
name: Calc Tags
27+
id: meta
28+
uses: docker/metadata-action@v5
2829
with:
29-
docker_image:{{ ` ${{ steps.config.outputs.repo }}` }}
30-
docker_registry:{{` ${{ steps.config.outputs.server }}` }}
31-
docker_username:{{` ${{ steps.config.outputs.username }}` }}
32-
docker_password:{{` ${{ secrets.` }}{{ pushkey}} }}
33-
34-
- name: Calculate image tags
35-
id: "tags"
36-
run: |
37-
while read -r tag; do
38-
tags="$tags {{`${{ steps.config.outputs.repo }}` }}:$tag"
39-
done < <(echo "{{`${{ steps.sver.outputs.version }}` }}")
40-
41-
echo target_tags=${tags} >> $GITHUB_OUTPUT
42-
43-
- name: Policy Login
30+
images: |
31+
${{ steps.config.outputs.server }}/${{ steps.config.outputs.repo }}
32+
flavor: |
33+
latest=auto
34+
tags: |
35+
type=semver,pattern={{version}}
36+
type=semver,pattern={{major}}.{{minor}}
37+
type=semver,pattern={{major}}
38+
# type=sha
39+
-
40+
name: Policy Login
4441
id: policy-login
4542
uses: opcr-io/policy-login-action@v3
4643
with:
4744
username: {{`${{ steps.config.outputs.username }}` }}
4845
password: {{`${{ secrets.`}}{{ pushkey }} }}
4946
server: {{`${{ steps.config.outputs.server }}` }}
50-
51-
- name: Policy Build
47+
-
48+
name: Policy Build
5249
id: policy-build
5350
uses: opcr-io/policy-build-action@v4
5451
with:
@@ -58,26 +55,26 @@ jobs:
5855
rego_version: "rego.v1"
5956
env:
6057
POLICY_DEFAULT_DOMAIN: {{`${{ steps.config.outputs.server }}` }}
61-
62-
- name: Policy Tag
58+
-
59+
name: Policy Tag
6360
id: policy-tag
6461
uses: opcr-io/policy-tag-action@v3
6562
with:
66-
source_tag: {{`${{ steps.config.outputs.repo }}` }}
67-
target_tags: {{`${{ steps.tags.outputs.target_tags }}` }}
63+
source_tag: ${{ steps.config.outputs.repo }}
64+
target_tags: ${{ steps.meta.outputs.tags }}
6865
env:
69-
POLICY_DEFAULT_DOMAIN: {{`${{ steps.config.outputs.server }}` }}
70-
71-
- name: Policy Push
66+
POLICY_DEFAULT_DOMAIN: ${{ steps.config.outputs.server }}
67+
-
68+
name: Policy Push
7269
id: policy-push
7370
uses: opcr-io/policy-push-action@v3
7471
with:
75-
tags: {{`${{ steps.tags.outputs.target_tags }}` }}
72+
tags: ${{ steps.meta.outputs.tags }}
7673
env:
77-
POLICY_DEFAULT_DOMAIN: {{`${{ steps.config.outputs.server }}` }}
78-
79-
- name: Policy Logout
74+
POLICY_DEFAULT_DOMAIN: ${{ steps.config.outputs.server }}
75+
-
76+
name: Policy Logout
8077
id: policy-logout
8178
uses: opcr-io/policy-logout-action@v3
8279
with:
83-
server: {{`${{ steps.config.outputs.server }}` }}
80+
server: ${{ steps.config.outputs.server }}

0 commit comments

Comments
 (0)