2014-08-26

Local-only delivery SMTP server

When you have a development server - a virtual machine or even a spare laptop - you eventually run into problem of email delivery because your application needs to send emails for whatever reason. Due to well known email spam problems the internet service provides typically no longer allow users to send email using unauthenticated SMTP connections.

I have a virtual machine running on my Fedora laptop where I write some test applications, and I travel from network to network every day so I cannot configure any outbound SMTP connections without exposing my SMTP credentials - which are btw. usually same as the IMAP credentials - to a configuration file of e.g. Postfix.

Local-only delivery to the rescue!

I've configure the virtual machine to forward all emails to my laptop, and told my laptop to deliver all email to a single local mailbox. Simple and efective. As additional bonus my crappy applications won't accidentally send spam our other unwanted emails to innocent bystanders...

On the virtual machine add this line to /etc/postfix/main.cf:

 relayhost = 192.168.122.1

If for some reason your physical host (laptop) has other bridge IP address you might want to adjust the IP...

On the physical host add these lines (don't forget to change the username) to /etc/postfix/main.cf:

 luser_relay = twillber@localhost
 local_recipient_maps =
 mydestination = pcre:/etc/postfix/localdeliverydestinations

On the physical host add this line to /etc/postfix/localdeliverydestinations:

 /.*/         ACCEPT

Restart your Postfixes and you should be ready to go!



2014-08-19

Test RHEL7 without installing it - on Docker!

So there's this new interesting operating system you'd like to try out? Traditionally you had to find a spare laptop where to install it on, and later on you installed them on virtual machines running on your laptop.

Nowadays things are even more easy; Docker provides an easy way to create software containers without you having to provision virtual machines or having to hunt for spare laptops.

Currently I'm running Fedora 20 on my laptop and in order to demonstrate stuff on RHEL7 all I need to do is to launch a RHEL7 in a container using Docker.

Couple of easy steps to test it out yourself:

Install Docker
On Fedora the RPM package is called "docker-io", let's install it first:

yum install docker-io

Add yourself to the Docker group so you don't need to use sudo later on:

sudo usermod -a -G docker $USER

Start Docker and enable it on boot time:
systemctl enable docker
systemctl start docker


Download RHEL7 base image

https://access.redhat.com/search/browse/docker-images#? -> "Red Hat Enterprise Linux 7 base image container in Docker Format"

Load the image into Docker and verify it's listed:

docker load -i ~/Downloads/rhel-server-docker-7.0-21.4-x86_64.tar.gz
docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
redhat/rhel         latest              e1f5733f050b        10 weeks ago        140.2 MB
rhel                latest              e1f5733f050b        10 weeks ago        140.2 MB
redhat/rhel7        0                   e1f5733f050b        10 weeks ago        140.2 MB
redhat/rhel7        0-21                e1f5733f050b        10 weeks ago        140.2 MB
redhat/rhel7        latest              e1f5733f050b        10 weeks ago        140.2 MB
rhel7               0                   e1f5733f050b        10 weeks ago        140.2 MB
rhel7               0-21                e1f5733f050b        10 weeks ago        140.2 MB
rhel7               latest              e1f5733f050b        10 weeks ago        140.2 MB

Start your RHEL7!
docker run -t -i rhel7 /bin/bash
bash-4.2# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)
bash-4.2# 

So what just happened? We told Docker to run "rhel7" image and start "/bin/bash". Option -t allocates a pseudo-tty (terminal) and -i is interactive mode. If you forget the flags your image is started in background.

You can use docker ps command to list running images, common use case is to open another terminal to do this while your image is running:

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
9469ec5c152b        redhat/rhel7:0      /bin/bash           4 seconds ago       Up 2 seconds                            distracted_ritchie   

Next steps

You'll probably want to learn about creating your own layered images, creating services within the image such as Apache or MySQL etc.

One good place to start learning is the Red Hat customer portal: https://access.redhat.com/articles/881893 "Get Started with Docker Containers in RHEL 7".


 

2014-08-14

Your first OpenShift Facebook application

Facebook [feys-boo k] - "to communicate with (a person) or search for information about (a person) by using Facebook" (dictionary.com)

They didn't have definition of OpenShift, but since you are reading this you probably know what it is. So you want to develop an application for Facebook and you wonder where to host it? That's one thing OpenShift can help you with.

The steps to create a simple Facebook application on OpenShift are very easy. I created a small "hello world" application with PHP to show how it's done.


Create OpenShift application

Go to OpenShift Online and create new PHP 5.3 application. I've used "facebooktest1" as the name here.



Clone the code to your laptop and download the Facebook PHP API v3 from here: https://github.com/facebook/facebook-php-sdk and copy the contents of the extracted src directory into your Openshift application:

git clone ssh://...
cd facebooktest1
cp -r ~/Downloads/facebook-php-sdk-master/src facebook


Create Facebook application

At https://developers.facebook.com create your Facebook application and add platform Facebook Canvas into it. Use the application URL from OpenShift as Canvas URL.

In this example I've used openshifttest1 as the application name.




Configure OpenShift environment variables

You'll need to set some environment variables in order to avoid having to insert Facebook App ID and App Secret into your source code. Namespace is your OpenShift domain name and application name is the OpenShift application name.


rhc set-env FBAPPID=365476396940042 --namespace twillber --app facebooktest1
rhc set-env FBAPPSECRET=hidden --namespace twillber --app facebooktest1

rhc set-env FBNAMESPACE=twillber-openshift --namespace twillber --app facebooktest1


Write the PHP application

Here is a very simple index.php just to show your Facebook name and user ID:


You can fetch the example code from here: http://people.redhat.com/~twillber/files/openshift/index.php.txt



Commit your code

At the end your directory structure should look like this:

[facebooktest1]$ tree
.
|-- facebook
|   |-- base_facebook.php
|   |-- facebook.php
|   `-- fb_ca_chain_bundle.crt
`-- index.php


1 directory, 4 files

Time to add the files and commit everything to OpenShift Online:

git add --all .
git commit -am 'created cool app'
git push


Demo time!

Browse to your application and enjoy your hard work: https://apps.facebook.com/twillber-openshift/