Skip to content

Commit 27cbbc5

Browse files
authored
Allow custom pre-script to be run (#88)
* Allow custom pre-script to be run
1 parent a474c13 commit 27cbbc5

5 files changed

Lines changed: 18 additions & 0 deletions

File tree

.github/workflows/pullpreview.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
registries: docker://${{ secrets.GHCR_PAT }}@ghcr.io
3737
# how long this instance will stay alive (each further commit will reset the timer)
3838
ttl: 1h
39+
# preinstall script to run on the instance before docker-compose is called, relative to the app_path
40+
pre_script: ./pre_script.sh
3941
env:
4042
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}"
4143
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}"

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ inputs:
6565
description: "Names of private registries to authenticate against. E.g. docker://username:password@ghcr.io"
6666
required: false
6767
default: ""
68+
pre_script:
69+
description: "Path to a bash script to run on the instance, before calling docker compose, relative to the app_path"
70+
required: false
71+
default: ""
6872
ttl:
6973
description: "Maximum time to live for deployments (e.g. 10h, 5d, infinite)"
7074
required: false
@@ -108,6 +112,8 @@ runs:
108112
- "${{ inputs.deployment_variant }}"
109113
- "--registries"
110114
- "${{ inputs.registries }}"
115+
- "--pre-script"
116+
- "${{ inputs.pre_script }}"
111117
- "--ttl"
112118
- "${{ inputs.ttl }}"
113119
env:

bin/pullpreview

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ up_opts = lambda do |o|
3737
o.array '--tags', 'Tags to add to the instance'
3838
o.array '--compose-files', 'Compose files to use when running docker-compose up', default: ["docker-compose.yml"]
3939
o.array '--compose-options', 'Additional options to pass to docker-compose up, comma-separated', default: ["--build"]
40+
o.string '--pre-script', 'Path to a bash script to run on the instance, before calling docker compose', default: ""
4041
end
4142

4243

examples/wordpress/pre_script.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
echo "Hello from pre_script.sh"
2+
echo "This is my current env:"
3+
env | sort

lib/pull_preview/instance.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Instance
1919
attr_reader :size
2020
attr_reader :tags
2121
attr_reader :access_details
22+
attr_reader :pre_script
2223

2324
class << self
2425
attr_accessor :client
@@ -48,6 +49,7 @@ def initialize(name, opts = {})
4849
@size = opts[:instance_type]
4950
@ssh_results = []
5051
@tags = opts[:tags] || {}
52+
@pre_script = opts[:pre_script]
5153
end
5254

5355
def launch_and_wait_until_ready!
@@ -177,6 +179,10 @@ def setup_prepost_scripts
177179
logger.warn "Registry ##{index} is invalid: #{e.message}"
178180
end
179181
end
182+
if pre_script && !pre_script.empty?
183+
tmpfile.puts "echo 'Attempting to run pre-script at #{pre_script}...'"
184+
tmpfile.puts "bash -e #{pre_script}"
185+
end
180186
tmpfile.flush
181187
unless scp(tmpfile.path, "/tmp/pre_script.sh", mode: "0755")
182188
raise Error, "Unable to copy the pre script on instance. Aborting."

0 commit comments

Comments
 (0)