From b03eea4fcae4ab768e4564f11bd26ee550fc4839 Mon Sep 17 00:00:00 2001 From: Nelson Hernandez Date: Mon, 6 Apr 2020 16:24:05 +0700 Subject: [PATCH 1/3] drone automation --- .drone.yml | 74 +++++++++++++++++++++++++++++++++++++++ .gitignore | 6 ++++ Dockerfile | 11 ++++-- github.json | 8 +++++ opt/AppRun | 4 +++ opt/build.sh | 4 ++- terraform/runtest.sh | 17 +++++++++ terraform/tmux-testing.tf | 64 +++++++++++++++++++++++++++++++++ terraform/userdata.sh | 48 +++++++++++++++++++++++++ 9 files changed, 233 insertions(+), 3 deletions(-) create mode 100644 .drone.yml create mode 100644 github.json create mode 100755 opt/AppRun create mode 100755 terraform/runtest.sh create mode 100644 terraform/tmux-testing.tf create mode 100644 terraform/userdata.sh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..68542ec --- /dev/null +++ b/.drone.yml @@ -0,0 +1,74 @@ +kind: pipeline +name: default + +steps: +## builds and pushes to hub.docker.com, the docker repo is just private right now. +- name: docker build + image: plugins/docker + settings: + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: nelsonenzo/tmux-appimage + tags: build-${DRONE_COMMIT} + +- name: copy artifact to s3 + image: nelsonenzo/tmux-appimage:build-${DRONE_COMMIT} + commands: + export AWS_ACCESS_KEY_ID=$${aws_access_key_id} + export AWS_ACCESS_SECRET_KEY=$${aws_access_secret_key} + aws s3 cp /opt/releases/tmux-3.0a-x86_64.AppImage tmux-appimage/${DRONE_COMMIT}/tmux-3.0a-x86_64.AppImage + +# copy the image to s3://tmux-appimage-builds/build-id/appimage + ## requires IAM key for S3 + ## change to update.sh script to pull Appimage from S3 + ## how to identify the build id in userdata or tags? +# - name: terraform test environment +# terraform: +# image: jmccann/drone-terraform:1 +# plan: false +# root_dir: terraform + +# terraform build 5 instances +# run tests +# if successful && branch == master + ## publish to github + ## push to s3/latest with zsync file. + ## destroy instances +# if fail + ## output command to ssh + + +# COMMENTING FOR NOW. THIS WORKS THOUGH. DO NOT DELETE. +# - name: create release on github +# image: nelsonenzo/tmux-appimage:692f3cf549ebbb95b5111845dc9f92a202e8d9a8 +# environment: +# FILE: /opt/releases/tmux-3.0a-x86_64.AppImage +# GITHUB_TOKEN: +# from_secret: personal_access_token +# commands: +# - | +# cat > github.json <<- EOM +# { +# "tag_name": "${DRONE_REPO_BRANCH}", +# "target_commitish": "${DRONE_REPO_BRANCH}", +# "name": "Tmux AppImage $RELEASE_TAG ${DRONE_REPO_BRANCH}", +# "body": "Appimage release for branch ${DRONE_REPO_BRANCH}", +# "draft": true, +# "prerelease": true +# } +# EOM +# - echo $(cat github.json) +# - | +# curl -X POST -d @github.json \ +# -H "Authorization: token $${GITHUB_TOKEN}" \ +# https://api.github.com/repos/nelsonenzo/tmux-appimage/releases > githubresponse.txt +# - echo $(cat githubresponse.txt) +# - export GITHUB_RELEASE_ID=$(jq .id githubresponse.txt) +# - echo $GITHUB_RELEASE_ID +# - | +# curl -H "Authorization: token $${GITHUB_TOKEN}" \ +# -H "Content-Type: $(file -b --mime-type $FILE)" \ +# --data-binary @$FILE \ +# "https://uploads.github.com/repos/nelsonenzo/tmux-appimage/releases/$GITHUB_RELEASE_ID/assets?name=$(basename $FILE)" diff --git a/.gitignore b/.gitignore index 892c59d..95bfc7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ opt/releases/* +localnotes/* +dronesecrets.txt +.terraform +terraform/notes.md +terraform.tfstate +terraform.tfstate.backup diff --git a/Dockerfile b/Dockerfile index de07516..4c9b032 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ ## Date: FROM centos:centos6.9 ## install build tools -RUN /usr/bin/yum groupinstall -y "Development Tools" -RUN /usr/bin/yum install -y wget +RUN /usr/bin/yum -y update && /usr/bin/yum groupinstall -y "Development Tools" && yum clean all +RUN /usr/bin/yum install -y wget && yum install -y epel-release && yum install -y jq RUN wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage \ && chmod +x linuxdeploy-x86_64.AppImage \ @@ -23,4 +23,11 @@ RUN sh autogen.sh && \ ./configure --prefix=/tmux/MakeBuild && \ make install +## complete the appimage build. +COPY ./opt /opt +RUN /opt/build.sh + +## Produces artifact +## /opt/releases/tmux-3.0a-x86_64.AppImage + CMD /opt/build.sh diff --git a/github.json b/github.json new file mode 100644 index 0000000..5d7a0ac --- /dev/null +++ b/github.json @@ -0,0 +1,8 @@ +{ +"tag_name": "drone", +"target_commitish": "drone", +"name": "Tmux AppImage 3.0a drone", +"body": "Appimage release for branch drone", +"draft": true, +"prerelease": true +} diff --git a/opt/AppRun b/opt/AppRun new file mode 100755 index 0000000..16c9944 --- /dev/null +++ b/opt/AppRun @@ -0,0 +1,4 @@ +#!/bin/bash +HERE="$(dirname "$(readlink -f "${0}")")" +unset ARGV0 +exec "${HERE}/usr/bin/tmux" "$@" diff --git a/opt/build.sh b/opt/build.sh index c37260d..42c9adf 100755 --- a/opt/build.sh +++ b/opt/build.sh @@ -8,4 +8,6 @@ export OUTPUT="/opt/releases/tmux-$RELEASE_TAG-x86_64.AppImage" /usr/bin/linuxdeploy --appdir=AppDir \ -i /opt/tmux-logo-square.png \ -d /opt/tmux.desktop \ - -e MakeBuild/bin/tmux --output=appimage + -e MakeBuild/bin/tmux \ + --custom-apprun=/opt/AppRun \ + --output=appimage diff --git a/terraform/runtest.sh b/terraform/runtest.sh new file mode 100755 index 0000000..9152cd8 --- /dev/null +++ b/terraform/runtest.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# arch_ip = ssh arch@75.101.221.166 +# debian_ip = ssh admin@18.215.146.13 +# redhat_ip = ssh ec2-user@3.91.243.203 +# suse_ip = ssh ec2-user@18.234.66.165 +# ubuntu_ip = ssh ubuntu@3.80.89.184 +hosts='arch@54.173.139.1 +admin@3.88.87.25 +ec2-user@54.221.128.205 +ec2-user@18.212.255.220 +ubuntu@18.234.82.136' + +for i in $hosts; do + echo $i + # ssh $i 'sudo -u root tmux ls; ls /touch-passed-true;' + ssh -o StrictHostKeyChecking=no $i 'cat /touch-passed-true && cat /session-passed-true' +done diff --git a/terraform/tmux-testing.tf b/terraform/tmux-testing.tf new file mode 100644 index 0000000..0958974 --- /dev/null +++ b/terraform/tmux-testing.tf @@ -0,0 +1,64 @@ +provider "aws" { + region = "us-east-1" + # shared_credentials_file = "/home/nelson/.aws/sso/cache/9cbcd2e573df943bafdb496ecb072776ba8ddecb.json" + # profile = "tools" +} + +# # Find the latest available AMI that is tagged with Component = web +# data "aws_ami" "ubuntu" { +# filter { +# name = "id" +# values = ["ami-07ebfd5b3428b6f4d"] +# } +# +# +# most_recent = true +# } + +resource "aws_instance" "ubuntu_1804" { + ami = "ami-07ebfd5b3428b6f4d" + instance_type = "t1.micro" + key_name = "personal-aws" + associate_public_ip_address = true + user_data = file("./userdata.sh") +} + +resource "aws_instance" "suse_linux" { + ami = "ami-0df6cfabfbe4385b7" + instance_type = "t1.micro" + key_name = "personal-aws" + associate_public_ip_address = true + user_data = file("./userdata.sh") +} + +resource "aws_instance" "redhat_enterprise" { + ami = "ami-0c322300a1dd5dc79" + instance_type = "t1.micro" + key_name = "personal-aws" + associate_public_ip_address = true + user_data = file("./userdata.sh") +} + +resource "aws_instance" "debian_stretch" { + ami = "ami-066027b63b44ebc0a" + instance_type = "t1.micro" + key_name = "personal-aws" + associate_public_ip_address = true + user_data = file("./userdata.sh") +} + +resource "aws_instance" "arch_linux" { + ami = "ami-0f040c7d22aedeb27" + instance_type = "t1.micro" + key_name = "personal-aws" + associate_public_ip_address = true + user_data = file("./userdata.sh") +} + + +output "ubuntu_ip" { value = "ubuntu@${aws_instance.ubuntu_1804.public_ip}" } +output "suse_ip" { value = "ec2-user@${aws_instance.suse_linux.public_ip}" } +output "redhat_ip" { value = "ec2-user@${aws_instance.redhat_enterprise.public_ip}" } +output "debian_ip" { value = "admin@${aws_instance.debian_stretch.public_ip}" } +output "arch_ip" { value = "arch@${aws_instance.arch_linux.public_ip}" } +# TERM=xterm sudo ./squashfs-root/usr/bin/tmux -2 diff --git a/terraform/userdata.sh b/terraform/userdata.sh new file mode 100644 index 0000000..5ac3ee7 --- /dev/null +++ b/terraform/userdata.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +DOWNLOAD=$(curl -s "https://api.github.com/repos/nelsonenzo/tmux-appimage/releases/tags/master" | grep browser_download_url | awk '{print $2}') +DOWNLOAD=$(sed -e 's/^"//' -e 's/"$//' <<<"$DOWNLOAD") +curl -L -s $DOWNLOAD --output /usr/local/bin/tmux +sudo chmod +x /usr/local/bin/tmux + +function touch-test { + sleep 1; + if grep -q 'touch: missing file operand' $HOME/touch-output.txt; then + echo 1 > $HOME/touch-passed-true + fi +} + +function validate_tmux_session_running { + tmux ls; + if [ $? = 0 ]; then + echo 1 > $HOME/session-passed-true + else + exit 1; + fi +} + +if which pacman; then + sudo pacman -Sy --noconfirm fuse2 + TERM=xterm tmux new -d -s touch-session 'touch > $HOME/touch-output.txt 2>&1;' + touch-test + TERM=xterm tmux -2 tmux new -d -s test-session +elif which yum; then + sudo yum install -y fuse + TERM=xterm tmux new -d -s touch-session 'touch > $HOME/touch-output.txt 2>&1;' + touch-test + TERM=xterm tmux -2 tmux new -d -s test-session +elif which zypper; then + sudo zypper install -y fuse + tmux new -d -s touch-session 'touch > $HOME/touch-output.txt 2>&1;' + touch-test + tmux new -d -s test-session +elif which apt-get; then + sudo apt-get install -y fuse + tmux new -d -s touch-session 'touch > $HOME/touch-output.txt 2>&1;' + touch-test + tmux new -d -s test-session +else + echo "no-package-manager" > tmux-env.txt +fi + +validate_tmux_session_running From e3253d05846ff49e736a43d273af9c15bbeff8eb Mon Sep 17 00:00:00 2001 From: Nelson Hernandez Date: Wed, 24 Jun 2020 11:15:01 -0700 Subject: [PATCH 2/3] update version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4c9b032..ead477e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous RUN yum install -y libevent2-devel.x86_64 ncurses-devel ## Change RELEASE_TAG to desired version/git sha -ENV RELEASE_TAG=3.0a +ENV RELEASE_TAG=3.1b RUN git clone https://github.com/tmux/tmux.git && cd tmux && git checkout $RELEASE_TAG WORKDIR /tmux From 922508e99237df3d12fa35fa5b2b2171f52550e0 Mon Sep 17 00:00:00 2001 From: Nelson Hernandez Date: Wed, 24 Jun 2020 11:26:10 -0700 Subject: [PATCH 3/3] tmux 3.1a --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ead477e..645142b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous RUN yum install -y libevent2-devel.x86_64 ncurses-devel ## Change RELEASE_TAG to desired version/git sha -ENV RELEASE_TAG=3.1b +ENV RELEASE_TAG=3.1a RUN git clone https://github.com/tmux/tmux.git && cd tmux && git checkout $RELEASE_TAG WORKDIR /tmux