NixOS-based container for running GitHub actions
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

remove unneeded script

-154
-154
push-container.nu
··· 1 - def main [ 2 - input: string # tar.gz file containing container image to be pushed to repository 3 - ...tags: string # Tags to be added to pushed container image 4 - --username: string = "" # username 5 - --password: string = "" # password 6 - --registry: string = "" # container registry 7 - --repository: string = "" # container repository 8 - --no-latest-tag # Don't add "latest" tag to list of tags 9 - --no-drone-tag # Don't add tag calculated from DRONE_BUILD_NUMBER and DRONE_COMMIT_SHA 10 - --no-github-tag # Don't add tag calculated from GITHUB_RUN_NUMBER and GITHUB_SHA 11 - ] { 12 - if not ($input | path exists) { 13 - print $"($input) does not exist!" 14 - exit 1 15 - } 16 - 17 - let tags = if not ($env | get -o PLUGIN_TAGS | is-empty) { 18 - $tags | append ($env.PLUGIN_TAGS | split row ',' | str trim) 19 - } else if not ($env | get -o INPUT_TAGS | is-empty) { 20 - $tags | append ($env.INPUT_TAGS | split row ',' | str trim) 21 - } else { 22 - $tags 23 - } 24 - 25 - let tags = if ( 26 - (not $no_github_tag) 27 - and 28 - (not ($env | get -o GITHUB_RUN_NUMBER | is-empty)) 29 - and 30 - (not ($env | get -o GITHUB_SHA | is-empty)) 31 - ) { 32 - $tags | append $"($env.GITHUB_RUN_NUMBER)-($env.GITHUB_SHA | str substring 0..7)" 33 - } else { 34 - $tags 35 - } 36 - 37 - let tags = if ( 38 - (not $no_drone_tag) 39 - and 40 - (not ($env | get -o DRONE_BUILD_NUMBER | is-empty)) 41 - and 42 - (not ($env | get -o DRONE_COMMIT_SHA | is-empty)) 43 - ) { 44 - $tags | append $"($env.DRONE_BUILD_NUMBER)-($env.DRONE_COMMIT_SHA | str substring 0..7)" 45 - } else { 46 - $tags 47 - } 48 - 49 - let tags = if (not $no_latest_tag) { 50 - $tags | append "latest" 51 - } else { 52 - $tags 53 - } 54 - 55 - let auth = {username: null, password: null} 56 - 57 - let auth = ( 58 - if not ($username | is-empty) and ($password | is-empty) { 59 - print "Got username and password from command line" 60 - {username: $username, password: $password} 61 - } else if ( 62 - (not ($env | get -o USERNAME | is-empty)) 63 - and 64 - (not ($env | get -o PASSWORD | is-empty)) 65 - ) { 66 - print "Got username and password from USERNAME and PASSWORD" 67 - {username: $env.USERNAME, password: $env.PASSWORD} 68 - } else if ( 69 - (not ($env | get -o PLUGIN_USERNAME | is-empty)) 70 - and 71 - (not ($env | get -o PLUGIN_PASSWORD | is-empty)) 72 - ) { 73 - print "Got username and password from PLUGIN_USERNAME and PLUGIN_PASSWORD" 74 - {username: $env.PLUGIN_USERNAME, password: $env.PLUGIN_PASSWORD} 75 - } else if ( 76 - (not ($env | get -o INPUT_USERNAME | is-empty)) 77 - and 78 - (not ($env | get -o INPUT_PASSWORD | is-empty)) 79 - ) { 80 - print "Got username and password from INPUT_USERNAME and INPUT_PASSWORD" 81 - {username: $env.INPUT_USERNAME, password: $env.INPUT_PASSWORD} 82 - } else if ( 83 - (not ($env | get -o GITHUB_ACTOR | is-empty)) 84 - and 85 - (not ($env | get -o GITHUB_TOKEN | is-empty)) 86 - ) { 87 - print "Got username and password from GITHUB_ACTOR and GITHUB_TOKEN" 88 - {username: $env.GITHUB_ACTOR, password: $env.GITHUB_TOKEN} 89 - } else { 90 - print "Unable to determine authentication parameters!" 91 - exit 1 92 - } 93 - ) 94 - 95 - let registry = ( 96 - if ($registry | is-empty) { 97 - if not ($env | get -o PLUGIN_REGISTRY | is-empty) { 98 - $env.PLUGIN_REGISTRY 99 - } else if not ($env | get -o INPUT_REGISTRY | is-empty) { 100 - $env.INPUT_REGISTRY 101 - } else if not ($env | get -o REGISTRY | is-empty) { 102 - $env.REGISTRY 103 - } else if ( 104 - (not ($env | get -o GITHUB_SERVER_URL | is-empty)) 105 - and 106 - (not ($env | get -o GITHUB_ACTOR | is-empty)) 107 - ) { 108 - $"($env.GITHUB_SERVER_URL)/($env.GITHUB_ACTOR)" 109 - } else { 110 - print "No registry specified!" 111 - exit 1 112 - } 113 - } else { 114 - $registry 115 - } 116 - ) 117 - 118 - let repository = ( 119 - if ($repository | is-empty) { 120 - if not ($env | get -o PLUGIN_REPOSITORY | is-empty) { 121 - $env.PLUGIN_REPOSITORY 122 - } else if not ($env | get -o INPUT_REPOSITORY | is-empty) { 123 - $env.INPUT_REPOSITORY 124 - } else if not ($env | get -o REPOSITORY | is-empty) { 125 - $env.REPOSITORY 126 - } else { 127 - print "No repository specified!" 128 - exit 1 129 - } 130 - } else { 131 - $repository 132 - } 133 - ) 134 - 135 - regctl registry login $registry --user $auth.username --pass $auth.password 136 - 137 - $tags | enumerate | each { 138 - |item| 139 - if $item.index == 0 { 140 - let new_image = $"($registry)/($repository):($item.item)" 141 - print $"Pushing ($new_image)" 142 - regctl image import $new_image $input 143 - print $"Pushed ($new_image)" 144 - } else { 145 - let old_image = $"($registry)/($repository):($tags | get 0)" 146 - let new_image = $"($registry)/($repository):($item.item)" 147 - print $"Copying ($old_image) ($new_image)" 148 - regctl image copy $old_image $new_image 149 - print $"Copied ($old_image) ($new_image)" 150 - } 151 - } 152 - 153 - regctl registry logout $registry 154 - }