diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 199d675b..59a92d9e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,6 +11,9 @@ jobs: build: name: Build Binaries runs-on: ubuntu-latest + permissions: + contents: read + id-token: write steps: - name: Checkout Codes uses: actions/checkout@v4 @@ -20,8 +23,8 @@ jobs: run: make ci # Run e2e test - #- name: Run E2e Test - # run: make e2e-test + - name: Run e2e Test + run: make e2e-test # Upload binaries - name: Upload Binaries @@ -33,6 +36,9 @@ jobs: build_push_image: name: Build and Push Images runs-on: ubuntu-latest + permissions: + contents: read + id-token: write needs: build if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }} steps: @@ -59,14 +65,22 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Declare Branch + - name: Read Secrets + uses: rancher-eio/read-vault-secrets@main + if: ${{ inputs.push == true }} + with: + secrets: | + secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ; + secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD + + - name: Login to Docker Hub run: | echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV" - name: Login to Docker Hub uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + username: ${{ env.DOCKER_USERNAME }} + password: ${{ env.DOCKER_PASSWORD }} # rancher/local-path-provisioner image - name: docker-publish @@ -75,7 +89,7 @@ jobs: with: context: ./ push: true - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/arm64, linux/arm tags: rancher/local-path-provisioner:${{ env.branch }}-head file: package/Dockerfile @@ -85,6 +99,6 @@ jobs: with: context: ./ push: true - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/arm64, linux/arm tags: rancher/local-path-provisioner:${{ github.ref_name }} file: package/Dockerfile diff --git a/main.go b/main.go index cddd4097..3f0c9a49 100644 --- a/main.go +++ b/main.go @@ -51,12 +51,12 @@ var ( EnvConfigMountPath = "CONFIG_MOUNT_PATH" ) -func cmdNotFound(c *cli.Context, command string) { +func cmdNotFound(_ *cli.Context, command string) { panic(fmt.Errorf("Unrecognized command: %s", command)) } -func onUsageError(c *cli.Context, err error, isSubcommand bool) error { - panic(fmt.Errorf("Usage error, please check your command")) +func onUsageError(_ *cli.Context, err error, _ bool) error { + panic(errors.Wrap(err, "Usage error, please check your command")) } func RegisterShutdownChannel(cancelFn context.CancelFunc) { diff --git a/package/Dockerfile b/package/Dockerfile index 3ce3b261..a25f36fb 100644 --- a/package/Dockerfile +++ b/package/Dockerfile @@ -3,12 +3,13 @@ FROM alpine ARG TARGETPLATFORM -RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \ +RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ] && [ "$TARGETPLATFORM" != "linux/arm/v7" ]; then \ echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \ exit 1; \ fi ENV ARCH ${TARGETPLATFORM#linux/} +ENV ARCH ${ARCH%/v7} RUN apk update RUN apk upgrade --no-cache busybox zlib diff --git a/provisioner.go b/provisioner.go index 1f86f0cb..9f774cc5 100644 --- a/provisioner.go +++ b/provisioner.go @@ -300,7 +300,7 @@ type pvMetadata struct { func pathFromPattern(pattern string, opts pvController.ProvisionOptions) (string, error) { metadata := pvMetadata{ PVName: opts.PVName, - PVC: opts.PVC.ObjectMeta, + PVC: opts.PVC.ObjectMeta, } tpl, err := template.New("pathPattern").Parse(pattern) @@ -317,7 +317,7 @@ func pathFromPattern(pattern string, opts pvController.ProvisionOptions) (string return buf.String(), nil } -func (p *LocalPathProvisioner) Provision(ctx context.Context, opts pvController.ProvisionOptions) (*v1.PersistentVolume, pvController.ProvisioningState, error) { +func (p *LocalPathProvisioner) Provision(_ context.Context, opts pvController.ProvisionOptions) (*v1.PersistentVolume, pvController.ProvisioningState, error) { cfg, err := p.pickConfig(opts.StorageClass.Name) if err != nil { return nil, pvController.ProvisioningFinished, err @@ -462,7 +462,7 @@ func (p *LocalPathProvisioner) provisionFor(opts pvController.ProvisionOptions, }, pvController.ProvisioningFinished, nil } -func (p *LocalPathProvisioner) Delete(ctx context.Context, pv *v1.PersistentVolume) (err error) { +func (p *LocalPathProvisioner) Delete(_ context.Context, pv *v1.PersistentVolume) (err error) { cfg, err := p.pickConfig(pv.Spec.StorageClassName) if err != nil { return err diff --git a/scripts/build b/scripts/build index 89f03a66..a41c1c53 100755 --- a/scripts/build +++ b/scripts/build @@ -12,6 +12,7 @@ fi LINKFLAGS="-X main.VERSION=$VERSION" CGO_ENABLED=0 GOARCH=amd64 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/local-path-provisioner-amd64 CGO_ENABLED=0 GOARCH=arm64 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/local-path-provisioner-arm64 +CGO_ENABLED=0 GOARCH=arm go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/local-path-provisioner-arm if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then GOOS=darwin go build -ldflags "$LINKFLAGS" -o bin/local-path-provisioner-darwin GOOS=windows go build -ldflags "$LINKFLAGS" -o bin/local-path-provisioner-windows diff --git a/test/util.go b/test/util.go index bdc93607..7aedec0b 100644 --- a/test/util.go +++ b/test/util.go @@ -12,6 +12,7 @@ import ( ) func createCmd(t *testing.T, cmd, kustomizeDir string, envs []string, callback func(*exec.Cmd)) *exec.Cmd { + t.Logf("creating command: %s", cmd) c := exec.Command("bash", "-c", cmd) c.Env = append(os.Environ(), envs...) c.Dir = kustomizeDir