Dieses Blog durchsuchen

Dienstag, 24. November 2015

Setup gitlab on ubuntu in 5 minutes with docker un ubuntu 15.04

Yesterday my virtualbox image on my external usb harddisk crashed and I quickly needed a new gitlab VM. I remembered my installation process last week, which tooked nearly an hour for a simple baseinstallation.

I didn't want to wait for a 2 h Vagrant imagedownload, so i decided to give docker a chance.

Docker on ubuntu 15.04 was installed in minutes.

1) Update ubuntu repos

Commandline:
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Open and add: 
sudo nano /etc/apt/sources.list.d/docker.list

Add
deb https://apt.dockerproject.org/repo ubuntu-vivid main

Save the file

Update your ubuntu
apt-get update



Install Docker
sudo apt-get install docker-engine

Start Docker
sudo service docker start
 
Pull gitlab on docker from docker hub
docker pull sameersbn/gitlab:8.2.0 

Download docker composer
wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml
 
Generate gitlab secretkey 
apt-get install pwd
genpwdgen Bsv1 64 
 
copy generated string an open downloaded docker-compose 
nano docker-compose.yml
 
search GITLAB_SECRETS_DB_KEY_BASE and set the generated secret
 
Install docker-composer
apt-get install docker-composer 


start gitlab composing
docker-compose up
 
 
Point your browser to http://localhost:10080 and login using the default username and password:

  • username: root
  • password: 5iveL!fe
 
 

 
 

Montag, 23. November 2015

Composer: checkout gitlab repo

I took a while to findout how to clone a external gitlabrepository via composer in a project

if your repository is available via git + ssh you have to create a  ssh key 

follow this link to do so
https://help.github.com/articles/generating-ssh-keys/

at next you have to add your ssh key to ssh-agent
exec ssh-agent bash
ssh-add ~/.ssh/id_rsa


 
composer.json in the root of your project

{
"repositories": [
    {
        "type":"vcs",
        "url":"git@gitlab:root/testproject2.git"
    }
],
 "require": {
        "peter1/peter2": "dev-master"
    },
"target-dir":"test"
}


peter1/peter2 = name of the repository in composer.json of repo you want to clone
target-dir = name of the directory in local folder "vendor"


the project you want to clone via composer needs a composer.json too.

{
    "name": "peter1/peter2",
    "description": "My New Project",
    "authors": [
        {
            "name": "Peter Böthig",
            "email": "mail@mymail.com"
        }
    ]
}

Sonntag, 22. November 2015

Magento2 constructors are not realy fair


This is the constructor of
Magento\Customer\Model\Address 
I know there are some disadvantages in usage of DI-Container. But a good architecture allows contextbased DI-Container, to prevent this kind of constructor mess. It could sound oldschool, but more then 3 parameter in a constructor is smelly.

This constrcutor contains 18 Parameters.

7 of the parameter are factories. I think its a good idea, to group the factories in a dedicated factory-di-container.
2 of are configobjects
2 are registries
1 Service

and so on.

Thats realy hard to learn and to refactore, if you have to change somethig in there.

What is best practice to prevent that?








Magento 2 generate new module the rapid way. Part I

Yesterday i was looking for the fastest way, to generate a module with an own entity, admingrid, editforms for the adminbackend etc.

In the past I have used UMC Module Creator for fast prototyping to bringup services rapidly. And I realy liked it on Magento 1.9  On Magento2 the UMC project ist still under heavy development, but the first results are very respactable. Some things are not available at the moment, but the mainfeatures of generating Models, Grids, Adminhtml are.

With this modulegenerator you are able to generate your Entitymodule in 20 minutes.

Lets start:

If you dont have a valid magento2 installation you can use my last install tutorial:
http://magento2-tuts.blogspot.de/2015/11/first-steps.html

At first I had to create a codefolder inside your magentoroot/app folder
 mkdir -p /var/www/html/magento2/app/code/Umc/Base  
 cd /var/www/html/magento2/app/code/Umc/Base  
 git clone https://github.com/UltimateModuleCreator/Umc_Base.git  
copy -fr Umc_Base/* /var/www/html/magento2/app/code/Umc/Base  

 This creates a folder Umc_Base with all the "good stuff" in it. You dont have to take care of registering the namespace, directory and all kind of that configuring stuff. Its all predefined. At the moment its not possible to store your module in the vendor folder. The magento devs will bringup this option later, as I can read in protokoll of a websession with devs and architects earlier this year.

After that you have to enable your extension on the new n98magerun based cli-tool

 cd /var/www/htm/magento2/bin  
 php magento module:enable Umc_Base  
 php magento setup:upgrade  
 php magento setup:di:compile   

the first cli-command enables the module.
the second one is neccessary to upgrade your database structure
the last command compiles the codebase and generates the output.

After that you will get a coreexception of a missing token. This seems to be a bug in Magento Core. You can ignore it for this time

After compiling you have to set your filesystem accessrights new, because the compiling process overrides it.
chmod -R 755 will do the trick (Do not use 755 in production)

 php magento cache:clear  

will clear the cache.

Now you can login in adminarea under
http://magento2.local/admin

A new mainnavigationpoint will come up "UMC" at the bottom of the navigation


After that the usage is almost selfdescribing.
Use the "new module" Button to get in the configscreen.
The formular helps you to get on it.

You can setup your namespace, version, companyname etc. On every field there is a helpfunction to get missing information.

After you have setup your entity, attributes etc you can save the module for downloading it.

Download your zippackage and unpack it. Copy the modulefolder unter
/var/www/html/magento/app/code

At last repeat the step to activate the module, like I descriped some minutes ago.

If everything worked fine, you should now have a new menupoint in the mainnavigation where you have defined your navigationlink.

If you open it you can directly see your new entity with all the known function
- editing
- inlineediting of a row (cool new stuff)
- exporting rows
- massactions
- deletes
- a searchfield with lucence support (new)

My module is named Workflowtask_Task. With that I can an any external workflowengine  to handle usertasks.





But lets see, what code was generated.

Here is my structure of the new module:




I do not want to explain much about the known structures. Most of the things seems to be similar to Magento1 with "little" architectural changes.
Even if these little changes are breaking all backward compatibility for all Modules you have used in the past, which is realy realy annoying and painfull to rewrite. Lets give Magento2 a chance here to have a deeper sight.

Controllers

As you can see all controllers now have only 1 action.  But for the moment I couldnt care less. As a magento2 developer you now have to setup a complete controller for each action.

Alan Storm says
In Magento 2, each controller has one, and only one, entry point. That’s the execute method. This is a step Magento 2’s architects took to help avoid conflicts with a large development teams all editing the same controller file for different features. 


That might be a good reason for that.
http://alanstorm.com/magento_2_mvvm_mvc

A very good deep view of controllers can be found on inchoo
http://inchoo.net/magento-2/magento-2-controllers/


In Part II we will show, how models, routing, di and template definitions are structured.

Thanks for now























Samstag, 21. November 2015

Magento 2 shortcut to create webapi on existing model

There is a way to call your modelmethods without to produce codeoverhead in defining interfaceclasses, datainterfaceclasses and double di definition in xml files via directlinking to your models in the webapi.xml definition of your <modulename>/webapi.xml

The object-instanciator-helper-class/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php

tries to instanciate all definitions in your modules webapi.xml.

Instead of defining the interface class in the webapi.xml and add it to the di container you can directly link to your modelclass in the webapi.xml.


 app/code/<vendorname>/<modulename>/etc/webapi.xml

 <routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">  
   <!-- Get taskinformation -->  <route url="/V1/test/workflowtask/:taskid" method="GET">  
     <service class="Test\Workflowtask\Model\Task" method="getByTaskid"/>  
   </route>  
 </routes>  


url is the url under which you want to reach your api
class is the class, which you want to instanciate
method is the method you want to call
parameter object defines the parameter you want to pass





The simple model looks like that:
app/code/<vendorname>/<modulename>/Models/Task.php
The Modelmethod we want to call via rest api is Task::getByTaskId()


A sample curl call on your model via api looks like that:

 curl -X GET "http://magento2.local/index.php/rest/V1/test/workflowtask/1" -H "Authorization: Bearer wiq2mg9en76fyn1fq9h14ctmryxfdu2h"

The bearer token for the request can be generated like that:
curl -X POST "http://magento2.local/index.php/rest/V1/integration/admin/token"      -H "Content-Type:application/json"      -d '{"username":"admin", "password":"test#123"}'









Magent2 WebApi Calls

Here are some samplecalls on the standard api.

http://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-token.html#xml-auth-request-syntax

I will bring up a tutorial how to create own apis in a while


First steps. Complete Installation on ubuntu LAMP Stack

Since half a year the community makes a big wind about magento 2.
I successfuly ignored it till November the 17. The day the 2.0 was released.

Now i want to have a look how to get in touch with it.

Magento 2 was released with the notice to use PHP7. But for Ubuntu 15.04 users there are no possibilities to get php7 up and running without to much playing arround. We want to lern magento, not "How to install PHP7 Beta on a not supported OS". Surely you can use vagrant or a VM with ubuntu 14.04 or CentOS.

So i decided to give 2.0 a try on ubuntu 15.04 with php 5.6.11
  

Apache 2.4
sudo apt-get install apache2 

MySql 5.6
sudo apt-get install mysql-server mysql-client

PHP5.5 (Magento)
sudo apt-get install php5 php5-intl libapache2-mod-php5 php5-mcrypt php5-gd php5-mysql php5-tidy php5-xmlrpc php5-xsl php5-curl php5-common php5-cli php5-ldap
service apache2 restart

sendmail
apt-get install sendmail

PHP.ini
At next an incompatibilty to php 7 has to be fixed. For that open
nano /etc/php5/apache2/php.ini
always_populate_raw_post_data =-1

php-mcrypt
a bug on ubuntu needs to be fixed for getting mcrypt running.
Otherwise you will get an installer error on setupscreen of magento2

sudo apt-get install mcrypt php5-mcrypt sudo php5enmod mcrypt sudo service apache2 restart

At next download an unpack magento 2 
https://www.magentocommerce.com/download
- unpack it under /var/www/html/magento

add a hostfile entry if you are on localhost
nano /etc/hosts
127.0.0.1 magento2.local 


Configure your apache 
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port t$
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName magento2.local

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/magento2


        <Directory "/var/www/html">
                AllowOverride  All
        </Directory>


        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

</VirtualHost>






After that browser to magent2.local
a readynesssceen will follow up and you can test 

The rest is well known. Follow the intallerscreen, put in your database credential to a existing database, you have created before and setup an adminuser to access adminarea.

New is that magento will suggest a secure unique adminarea url, to prevent hacks on standard routs, happend very often in the past.