Skip to content

Commit

Permalink
PR add godpod.io integration with git gpg support (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
strausmann authored Mar 28, 2022
1 parent dd16fc8 commit da0221e
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM gitpod/workspace-mysql

USER root

# Update APT Database
### base ###
RUN apt-get update -q \
&& apt-get install -y php-dev

# Install XDebug
RUN curl -sSf http://xdebug.org/files/xdebug-3.1.3.tgz | tar xz \
&& cd xdebug-3.1.3 \
&& phpize \
&& ./configure \
&& make install -j$(nproc) \
&& printf 'zend_extension=xdebug\n[XDebug]\nxdebug.remote_enable=1\nxdebug.remote_autostart=1\n' > /etc/php/7.4/mods-available/xdebug.ini \
&& ln -sf /etc/php/7.4/mods-available/xdebug.ini "$(php-config --ini-dir)/20-xdebug.ini"

# Install latest composer v2 release
RUN curl -sSf https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \
&& mkdir -p /home/gitpod/.config \
&& chown -R gitpod:gitpod /home/gitpod/.config

USER gitpod

# Install Changelogger
RUN composer global require churchtools/changelogger

# Add Workspace/Project composer bin folder to $PATH
ENV PATH="$PATH:$HOME/.config/composer/vendor/bin:$GITPOD_REPO_ROOT/vendor/bin"
21 changes: 21 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
image:
file: .gitpod.Dockerfile

ports:
- port: 8000
onOpen: open-browser
- port: 3306
onOpen: ignore
- port: 33060
onOpen: ignore

# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/
tasks:
- before: bash .gp/bash/before-tasks.sh
init: |
composer install -o -n
name: Main Terminal

vscode:
extensions:
- felixfbecker.php-debug
74 changes: 74 additions & 0 deletions .gp/bash/before-tasks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash
#
# SPDX-License-Identifier: MIT
# Copyright © 2021 Apolo Pena
#
# before-tasks.sh
# Description:
# Tasks that should be run every time the workspace is created or started.
#
# Notes:
# Gitpod currently does not persist files in the home directory so we must write them
# in everytime the workspace starts. This is done in the 'before' task in .gitpod.yml

# BEGIN: Enable GPG key to sign Git commits.
# Error handling for improper use of GPG environment variables
err_msg_prefix1="A GPG_KEY was found but it's corresponding GPG_KEY_ID was not."
err_msg_prefix2="A GPG_KEY_ID was found but it's corresponding GPG_KEY was not."
err_msg_suffix="Git commits will not be signed."
[[ -n $GPG_KEY && -z $GPG_KEY_ID ]] &&
echo "ERROR: $err_msg_prefix1 $err_msg_suffix"
[[ -n $GPG_KEY_ID && -z $GPG_KEY ]] &&
echo "ERROR: $err_msg_prefix2 $err_msg_suffix"
# Main GPG key logic
if [[ -n $GPG_KEY && -n $GPG_KEY_ID ]]; then
gpg_conf_path=~/.gnupg/gpg.conf
msg="Enabling Git commit signing for GPG key id: $GPG_KEY_ID"
gpg -q --batch --import <(echo "$GPG_KEY" | base64 -d) &&
echo 'pinentry-mode loopback' >> "$gpg_conf_path" &&
git config --global user.signingkey "$GPG_KEY_ID" &&
git config commit.gpgsign true
ec=$?
if [[ $ec -eq 0 ]]; then
echo "SUCCESS: $msg"
# Change the git email if the user needs it (ensures the commit is marked as 'Verified')
if [[ -n $GPG_MATCH_GIT_TO_EMAIL ]]; then
msg="Setting user.email in ~/.gitconfig to $GPG_MATCH_GIT_TO_EMAIL"
if git config --global user.email "$GPG_MATCH_GIT_TO_EMAIL"; then
echo "SUCCESS: $msg"
else
echo "ERROR: $msg"
fi
fi
# Ultimately trust the key, bump to lowercase and check the value of the directive
if [[ $(echo "$GPG_AUTO_ULTIMATE_TRUST" | tr '[:upper:]' '[:lower:]') == yes ]]; then
msg="Automagically giving ultimate trust to GPG_KEY_ID: $GPG_KEY_ID"
# Prepend the key id as a trusted hex and update the local database with a silent arbitrary gpg call
echo -e ""trusted-key 0x"$GPG_KEY_ID""\n$(cat $gpg_conf_path)" > "$gpg_conf_path" &&
gpg --list-keys &> /dev/null
ec=$?
if [[ $ec -eq 0 ]]; then
echo "SUCCESS: $msg"
else
echo "ERROR: $msg"
fi
fi
else
echo "ERROR: $msg"
fi
fi
# END: Enable GPG key to sign Git commits.

# Auto activate intelephense if license key is available
if [[ -n $INTELEPHENSE_LICENSEKEY ]]; then
msg="creating $HOME/intelephense/licence.txt"
echo "INTELEPHENSE_LICENSEKEY environment variable found, $msg"
mkdir -p "$HOME/intelephense" &&
echo "$INTELEPHENSE_LICENSEKEY" > "$HOME/intelephense/licence.txt" &&
ec=$?
if [[ $ec -eq 0 ]]; then
echo "SUCCESS: $msg"
else
echo "ERROR: $msg"
fi
fi
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![Coverage Status](https://coveralls.io/repos/github/mlocati/ip-lib/badge.svg?branch=master)](https://coveralls.io/github/mlocati/ip-lib?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mlocati/ip-lib/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mlocati/ip-lib/?branch=master)
![Packagist Downloads](https://img.shields.io/packagist/dm/mlocati/ip-lib)
[![Open in Gitpod](https://img.shields.io/badge/Open%20in-Gitpod-%232cb64c?logo=gitpod)](https://gitpod.io/#https://github.com/mlocati/ip-lib)

# IPLib - Handle IPv4, IPv6 and IP ranges

Expand Down Expand Up @@ -643,6 +644,25 @@ var_export((string) Factory::parseAddressString('127.0.0.0xff:80', ParseStringFl
var_export((string) Factory::parseAddressString('[::%11]:80', ParseStringFlag::MAY_INCLUDE_PORT | ParseStringFlag::MAY_INCLUDE_ZONEID));
```

## Gitpod Environment Variables

The following features can be enabled through environment variables that have been set in your [Gitpod preferences](https://gitpod.io/variables).:

\* _Please note that storing sensitive data in environment variables is not ultimately secure but should be OK for most development situations._
- ### Sign Git commits with a GPG key
- `GPG_KEY_ID` (required)
- The ID of the GPG key you want to use to sign your git commits
- `GPG_KEY` (required)
- Base64 encoded private GPG key that corresponds to your `GPG_KEY_ID`
- `GPG_MATCH_GIT_TO_EMAIL` (optional)
- Sets your git user.email in `~/.gitconfig` to the value provided
- `GPG_AUTO_ULTIMATE_TRUST` (optional)
- If the value is set to `yes` or `YES` then your `GPG_KEY` will be automatically ultimately trusted
- ### Activate an Intelliphense License Key
- `INTELEPHENSE_LICENSEKEY`
- Creates `~/intelephense/licence.txt` and will contain the value provided
- This will activate [Intelliphense](https://intelephense.com/) for you each time the workspace is created or restarted

## Do you really want to say thank you?

You can offer me a [monthly coffee](https://github.com/sponsors/mlocati) or a [one-time coffee](https://paypal.me/mlocati) :wink:

0 comments on commit da0221e

Please sign in to comment.