Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
dea294c
update from base
mfittko Oct 11, 2021
1579d20
remove swapping, shrink /dev/shm
mfittko Oct 11, 2021
10e15fe
refactor provisioning
mfittko Oct 19, 2021
3651b58
update compose
mfittko Oct 19, 2021
8ebf31d
cop fix
mfittko Oct 19, 2021
6c12605
minor fixes
mfittko Oct 19, 2021
666bd1f
update pry
mfittko Oct 19, 2021
a68764c
add gemspec
mfittko Oct 19, 2021
65efb50
fix deprecation
mfittko Oct 19, 2021
4a346a2
update gemspec
mfittko Oct 19, 2021
96b8eca
update gemspec
mfittko Oct 19, 2021
6839b54
try to fix require
mfittko Oct 19, 2021
9c93a0e
one more
mfittko Oct 19, 2021
345077b
bump version
mfittko Oct 19, 2021
e7c19ac
use glob again
mfittko Oct 19, 2021
82954fa
remove unknown argument for tar
korny Mar 12, 2022
6cbe1f9
Merge branch 'master' into master
mfittko Mar 18, 2022
618d7b3
Merge remote-tracking branch 'origin/master' into init_cmd
mfittko Mar 18, 2022
1efb4d5
skip ip prefix
mfittko May 18, 2022
bf6acb7
source env by default
mfittko May 18, 2022
3da00b8
allow passing in instance subdomain via CLI cmd
mfittko May 26, 2022
ec6c42e
add optional basic_auth via BASIC_AUTH=user:pass ENV variable
mfittko May 27, 2022
2fe79a2
try hardcoded basic auth
mfittko May 27, 2022
b78016f
Revert "try hardcoded basic auth"
mfittko May 27, 2022
ad36e4c
ignore all unknown actions
mfittko May 27, 2022
f9e1bf0
make github sync more robust
mfittko Jun 1, 2022
c40d19e
fix dockerhub login
mfittko Jun 7, 2022
f2de689
only use first admin for initial ssh setup
mfittko Jun 15, 2022
2bf4bf3
fix security threat by opening too many ports by default. we should b…
mfittko Jun 20, 2022
decb5bb
use base image for faster builds
mfittko Jun 27, 2022
f3bad2b
revert (no access to dockerhub)
mfittko Jun 27, 2022
3ed7e53
use trailing slash for basic auth to be stripped from location
mfittko Jun 27, 2022
38f7d30
revert
mfittko Jun 29, 2022
b667a40
change label
mfittko Jun 29, 2022
06bb0c0
add deploy_key
mfittko Aug 16, 2022
85642f3
update compose version
mfittko Aug 31, 2022
1483247
try more often, pick random availablity zone
mfittko Sep 14, 2022
b721463
tackle docker not having been shut down cleanly on snapshot creation
mfittko Sep 14, 2022
01893ab
switch to using amazon linux 2 since the old blueprint became unavail…
mfittko Jan 6, 2023
28f2978
Merge remote-tracking branch 'origin/amazon-linux-2' into sofatutor
mfittko Jan 6, 2023
1300b80
remove docker volume cleanup
mfittko Jan 11, 2023
6fa534a
make username/password optional
mfittko Feb 17, 2023
f0febba
enable docker in systemctl on start
mfittko Feb 17, 2023
f8d0df1
add publish action
mfittko Feb 24, 2023
d813738
Merge branch 'master' into sofatutor
mfittko Feb 24, 2023
0d4ea75
run on sofatutor branch
mfittko Feb 24, 2023
94ece4a
Merge remote-tracking branch 'origin/sofatutor' into sofatutor
mfittko Feb 24, 2023
851f290
add tag
mfittko Feb 24, 2023
65e4b55
use fixed value
mfittko Feb 24, 2023
754217e
add docker:// prefix
mfittko Feb 24, 2023
9a4aa56
clean apt cache
mfittko Feb 26, 2023
53439df
show all logs on error
mfittko Feb 28, 2023
7d22102
upload and tar together
mfittko Feb 28, 2023
8b1ede9
use correct image
mfittko Feb 28, 2023
e2c5c61
fix missing cmd
mfittko Feb 28, 2023
0ed4c7f
no verbose
mfittko Feb 28, 2023
5e97620
fix path
mfittko Feb 28, 2023
026a9a0
show upload size
mfittko Feb 28, 2023
6ba17f8
show upload size
mfittko Feb 28, 2023
77a54a5
use logger
mfittko Feb 28, 2023
171df05
revert
mfittko Feb 28, 2023
1d82eda
reduce fatal error log size
mfittko Mar 2, 2023
7a352aa
fix output
mfittko May 19, 2023
0357b59
make sure that we can use a simple instance_type (e.g. medium) and be…
mfittko Jul 3, 2023
5858073
remove trailing slash
mfittko May 15, 2024
c2e99a5
Update terminal-table to 3.0.2, adjust dependencies, and bump version…
mfittko Oct 21, 2024
1e14c30
Update dependencies for aws-sdk-lightsail, octokit, and slop
mfittko Oct 21, 2024
2de72ef
use sofatutor's forked docker actions
mfittko Nov 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.
---
name: Create and publish a Container image

on:
push:
branches:
- sofatutor
tags:
- "v*"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.event.repository.owner.name }}/pullpreview

jobs:
build-and-push-image:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: sofatutor/docker-login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: sofatutor/docker-metadata-action@57396166ad8aefe6098280995947635806a0e6ea
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}

- name: Build and push Docker image
uses: sofatutor/docker-build-push-action@c56af957549030174b10d6867f20e78cfd7debc5
with:
context: .
push: true
pull: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion .github/workflows/pullpreview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
if: github.event_name == 'schedule' || github.event_name == 'push' || github.event.label.name == 'pullpreview' || contains(github.event.pull_request.labels.*.name, 'pullpreview')
if: github.event_name == 'schedule' || github.event_name == 'push' || github.event.label.name == 'preview' || contains(github.event.pull_request.labels.*.name, 'preview')
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## master

- Add optional `PULLPREVIEW_SNAPSHOT_NAME` environment variable, which can be used to restore from a specific snapshot name rather than a snapshot for a specific instance name.
- Add optional `PULLPREVIEW_ENV_VARS` environment variable, which can be passed through, to set any environment variables during launch/update.
- Add optional `PULLPREVIEW_LAUNCH_COMMAND` environment variable, which can be passed through, to replace docker-compose launch/update commands.

## v5 - updated on 20230110

- Switch to using amazon linux 2 since the old blueprint became unavailable (#34)
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ruby:2.7-slim

RUN apt-get update -qq && apt-get install openssh-client git -y
RUN apt-get update -qq && apt-get install openssh-client git -y \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY Gemfile .
COPY Gemfile.lock .
Expand Down
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ GEM
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-lightsail (1.30.0)
aws-sdk-lightsail (1.32.0)
aws-sdk-core (~> 3, >= 3.71.0)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.1.3)
aws-eventstream (~> 1.0, >= 1.0.2)
coderay (1.1.2)
coderay (1.1.3)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
jmespath (1.4.0)
method_source (1.0.0)
multipart-post (2.1.1)
octokit (4.18.0)
octokit (4.22.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
pry (0.13.1)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (4.0.6)
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
slop (4.8.1)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
slop (4.10.1)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (1.7.0)

PLATFORMS
Expand All @@ -47,4 +47,4 @@ DEPENDENCIES
terminal-table

BUNDLED WITH
2.1.4
2.4.22
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inputs:
ports:
description: "Ports to open for external access on the preview server (port 22 is always open), comma-separated"
required: false
default: "80/tcp,443/tcp,1000-10000/tcp"
default: "80/tcp,443/tcp"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be pulled to upstream (security issue)

cidrs:
description: "The IP address, or range of IP addresses in CIDR notation, that are allowed to connect to the instance"
required: false
Expand All @@ -46,6 +46,10 @@ inputs:
description: "Names of private registries to authenticate against. E.g. docker://username:password@ghcr.io"
required: false
default: ""
deploy_key:
description: "Additional public SSH key used for authentication"
required: false
default: ""
Comment on lines +49 to +52
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove


outputs:
url:
Expand All @@ -57,7 +61,7 @@ outputs:

runs:
using: "docker"
image: "Dockerfile"
image: docker://ghcr.io/sofatutor/pullpreview:sofatutor
args:
- "github-sync"
- "${{ inputs.app_path }}"
Expand Down
4 changes: 3 additions & 1 deletion bin/pullpreview
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ up_opts = lambda do |o|
o.array '--registries', 'URIs of docker registries to authenticate against, e.g. docker://username:password@ghcr.io', default: []
o.string '--dns', 'Enable DNS support for pretty-looking URLs', default: "my.pullpreview.com"
o.array '--ports', 'Ports to open for external access on the preview server', default: [
"80/tcp", "443/tcp", "1000-10000/tcp"
"80/tcp", "443/tcp"
]
o.string '--instance-type', 'Instance type to use', default: 'small_2_0'
o.string '--default-port', 'Default port to use when displaying the instance hostname', default: "80"
o.array '--tags', 'Tags to add to the instance'
o.array '--compose-files', 'Compose files to use when running docker-compose up', default: ["docker-compose.yml"]
o.string '--deploy-key', 'Additional public SSH key (optional)'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

o.string '--subdomain', 'Instance subdomain (optional)'
end

begin
Expand Down
28 changes: 18 additions & 10 deletions data/update_script.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set -o pipefail

APP_TARBALL="$1"
APP_PATH="<%= locals.remote_app_path %>"
PULLPREVIEW_LAUNCH_COMMAND="<%= locals.custom_launch_command %>"
PULLPREVIEW_ENV_VARS="<%= locals.custom_env_vars %>"
PULLPREVIEW_ENV_FILE="/etc/pullpreview/env"

lock_file="/tmp/update.lock"
Expand Down Expand Up @@ -51,30 +53,36 @@ echo 'PULLPREVIEW_PUBLIC_IP=<%= locals.public_ip %>' >> $PULLPREVIEW_ENV_FILE
echo 'PULLPREVIEW_URL=<%= locals.url %>' >> $PULLPREVIEW_ENV_FILE
echo "PULLPREVIEW_FIRST_RUN=$PULLPREVIEW_FIRST_RUN" >> $PULLPREVIEW_ENV_FILE

if [ -n "${PULLPREVIEW_ENV_VARS}" ] ; then
while read -d, -r pair; do
IFS='=' read -r key val <<<"$pair"
echo "$key=$val" >> $PULLPREVIEW_ENV_FILE
done <<<"$PULLPREVIEW_ENV_VARS,"
fi

Comment on lines +56 to +62
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PULLPREVIEW_ENV_VARS feature can be pulled to separate PR

set -o allexport
source $PULLPREVIEW_ENV_FILE
set +o allexport

cd /

sudo rm -rf "$APP_PATH"
sudo mkdir -p "$APP_PATH"
sudo chown -R ec2-user.ec2-user "$APP_PATH"
tar xzf "$1" -C "$APP_PATH"
sudo rm -rf "/tmp$APP_PATH"
sudo mkdir -p "$APP_PATH" "/tmp$APP_PATH"
sudo chown -R ec2-user.ec2-user "$APP_PATH" "/tmp$APP_PATH"
tar xzf "$1" -C "/tmp$APP_PATH"
rsync -auz "/tmp$APP_PATH" / --remove-source-files --delete
Comment on lines +69 to +73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be pulled to upstream: Makes sure that "$APP_PATH" does not end up being a zombie path when docker is still running on it with mirrored volumes attached.


cd "$APP_PATH"

echo "Cleaning up..."
docker volume prune -f || true

echo "Updating dependencies..."
yum update -y || true

if ! /tmp/pre_script.sh ; then
echo "Failed to run the pre-script"
exit 1
fi

if [ -n "${PULLPREVIEW_LAUNCH_COMMAND}" ] ; then
echo "Command to be executed: $PULLPREVIEW_LAUNCH_COMMAND"
bash -c "$PULLPREVIEW_LAUNCH_COMMAND" ; exit $?
fi

pull() {
docker-compose <%= locals.compose_files.map{|f| ["-f", f.inspect]}.flatten.join(" ") %> pull -q
Expand Down
20 changes: 15 additions & 5 deletions lib/pull_preview/github_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GithubSync
attr_reader :opts
attr_reader :always_on

LABEL = "pullpreview"
LABEL = "preview"

def self.run(app_path, opts)
github_event_name = ENV.fetch("GITHUB_EVENT_NAME")
Expand All @@ -23,7 +23,20 @@ def self.run(app_path, opts)
# https://help.github.com/en/actions/reference/events-that-trigger-workflows
github_context = JSON.parse(File.read(github_event_path))
PullPreview.logger.debug "github_context = #{github_context.inspect}"
self.new(github_context, app_path, opts).sync!
github_sync = new(github_context, app_path, opts)
begin
seconds ||= 0.2
github_sync.sync!
rescue => e
if seconds > 30
raise e
github_sync.update_github_status(:error)
end

sleep seconds
seconds *= 2
retry
end
end

# Go over closed pull requests that are still labelled as "pullpreview", and force the destroyal of the corresponding environments
Expand Down Expand Up @@ -116,9 +129,6 @@ def sync!
else
PullPreview.logger.info "Ignoring event #{pp_action.inspect}"
end
rescue => e
update_github_status(:error)
raise e
end

def guess_action_from_event
Expand Down
Loading