Skip to content

Commit

Permalink
Packages support file permissions and ownership (#23)
Browse files Browse the repository at this point in the history
* Add support for specifying file permissions inside a package
* Add support for specifying file ownership inside a package
  • Loading branch information
shore authored Jun 12, 2024
1 parent 33f7d23 commit 35f4725
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 30 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ jobs:
license: MPL-2.0
binary: ${{ steps.build.outputs.binary-path }}
bin_path: /usr/local/bin
file_permissions: 0o027
user_owner: root
group_owner: vault

- name: dump RPM
run: |
echo "::group::maybe install rpm" 1>&2
# runner is ubuntu, install rpm if it's not already available
which rpm || apt install -y rpm
echo "::endgroup::" 1>&2
rpm -qplv out/*.rpm
- name: dump deb
run: |
dpkg -c out/*.deb
15 changes: 15 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ inputs:
description: 'Path to install the binary at'
default: '/usr/bin'
required: false
file_permissions:
description: 'File permissions applied to all files in the package; specify in yaml/octal format: `0o022`; if empty, permissions are unmodified.'
default: ''
required: false
user_owner:
description: 'The user name or ID that should own the files in the package; e.g.: root'
default: ''
required: false
group_owner:
description: 'The group name or ID that should own the files in the package; e.g.: root'
default: ''
required: false
config_dir:
description: 'Directory of configs in desired filesystem structure.'
default: ''
Expand Down Expand Up @@ -197,6 +209,9 @@ runs:
INPUT_DEPENDS: ${{ inputs.depends }}
INPUT_BINARY: ${{ inputs.binary }}
INPUT_BIN_PATH: ${{ inputs.bin_path }}
INPUT_FILEPERMISSIONS: ${{ inputs.file_permissions }}
INPUT_USEROWNER: ${{ inputs.user_owner }}
INPUT_GROUPOWNER: ${{ inputs.group_owner }}
INPUT_CONFIG_DIR: ${{ inputs.config_dir }}
INPUT_PREINSTALL: ${{ inputs.preinstall }}
INPUT_POSTINSTALL: ${{ inputs.postinstall }}
Expand Down
93 changes: 63 additions & 30 deletions fpm_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ import (
)

type NfpmInput struct {
Name string
Arch string
Version string
Maintainer string
Vendor string
Description string
Homepage string
License string
Depends []string
Binary string
BinaryDest string
Preinstall string
Postinstall string
Preremove string
Postremove string
Name string
Arch string
Version string
Maintainer string
Vendor string
Description string
Homepage string
License string
Depends []string
Binary string
BinaryDest string
Preinstall string
Postinstall string
Preremove string
Postremove string
UserOwner string
GroupOwner string
FilePermissions string

ConfigFiles []*ConfigFile
}
Expand Down Expand Up @@ -90,6 +93,9 @@ func main() {
inputPostinstall := os.Getenv("INPUT_POSTINSTALL")
inputPreremove := os.Getenv("INPUT_PREREMOVE")
inputPostremove := os.Getenv("INPUT_POSTREMOVE")
inputPermissions := os.Getenv("INPUT_FILEPERMISSIONS")
inputUserOwner := os.Getenv("INPUT_USEROWNER")
inputGroupOwner := os.Getenv("INPUT_GROUPOWNER")

depends := strings.Split(inputDepends, ",")
if inputDepends == "" {
Expand All @@ -109,21 +115,24 @@ func main() {
}

input := &NfpmInput{
Name: inputName,
Arch: inputArch,
Version: inputVersion,
Maintainer: inputMaintainer,
Vendor: inputVendor,
Description: inputDescription,
Homepage: inputHomepage,
License: inputLicense,
Depends: depends,
Binary: inputBinary,
BinaryDest: binDest,
Preinstall: inputPreinstall,
Postinstall: inputPostinstall,
Preremove: inputPreremove,
Postremove: inputPostremove,
Name: inputName,
Arch: inputArch,
Version: inputVersion,
Maintainer: inputMaintainer,
Vendor: inputVendor,
Description: inputDescription,
Homepage: inputHomepage,
License: inputLicense,
Depends: depends,
Binary: inputBinary,
BinaryDest: binDest,
Preinstall: inputPreinstall,
Postinstall: inputPostinstall,
Preremove: inputPreremove,
Postremove: inputPostremove,
FilePermissions: inputPermissions,
UserOwner: inputUserOwner,
GroupOwner: inputGroupOwner,
}

input.ConfigFiles = findConfigs(inputConfigDir)
Expand Down Expand Up @@ -153,16 +162,40 @@ depends:
- {{ . }}
{{- end }}
{{- end }}
{{- if ne .FilePermissions "" }}
umask: {{ .FilePermissions }}
{{- end }}
contents:
{{- if ne .Binary "" }}
- src: {{ .Binary }}
dst: {{ .BinaryDest }}
{{- if or (ne .UserOwner "") (ne .GroupOwner "") }}
file_info:
{{- if ne .UserOwner "" }}
owner: root
{{- end }}
{{- if ne .GroupOwner "" }}
group: vault
{{- end }}
{{- end }}
{{- end }}
{{- /* capture ownership for use in .ConfigFiles subcontext */ -}}
{{- $userOwner := .UserOwner }}
{{- $groupOwner := .GroupOwner }}
{{- with .ConfigFiles }}
{{- range $index, $element := . }}
- src: {{ .LocalPath }}
dst: {{ .DestPath }}
type: config|noreplace
{{- if or (ne $userOwner "") (ne $groupOwner "") }}
file_info:
{{- if ne $userOwner "" }}
owner: root
{{- end }}
{{- if ne $groupOwner "" }}
group: vault
{{- end }}
{{- end }}
{{- end }}
{{- end }}
scripts:
Expand Down

0 comments on commit 35f4725

Please sign in to comment.