Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker runner #72

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions plugin-docker/che-plugin-docker-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2012-2015 Codenvy, S.A.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html

Contributors:
Codenvy, S.A. - initial API and implementation

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-plugin-docker-runner-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>3.11.7-SNAPSHOT</version>
</parent>
<artifactId>che-plugin-docker-client</artifactId>
<packaging>jar</packaging>
<name>Che Plugin :: Docker Runner :: Docker Client</name>
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>${org.bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
<version>${che.core.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright (c) 2012-2015 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.docker;

/**
* Implementation of docker AuthConfig object
* @see <a href="https://github.com/docker/docker/blob/v1.6.0/registry/auth.go#L29">source</a>
* @author andrew00x
*/
public class AuthConfig {
private String serveraddress;
private String username;
private String password;
private String email;
private String auth;


public AuthConfig(String serveraddress, String username, String password, String email, String auth) {
this.serveraddress = serveraddress;
this.username = username;
this.password = password;
this.email = email;
this.auth = auth;
}

public AuthConfig(String serveraddress, String username, String password, String email) {
this.serveraddress = serveraddress;
this.username = username;
this.password = password;
this.email = email;
this.auth = "";
}

public AuthConfig(AuthConfig other) {
this.serveraddress = other.serveraddress;
this.username = other.username;
this.password = other.password;
this.email = other.email;
this.auth = other.auth;
}

public AuthConfig() {
}

public String getServeraddress() {
return serveraddress;
}

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public void setServeraddress(String serveraddress) {
this.serveraddress = serveraddress;
}

public void setUsername(String username) {
this.username = username;
}

public void setPassword(String password) {
this.password = password;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getAuth() {
return auth;
}

public void setAuth(String auth) {
this.auth = auth;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2012-2015 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.docker;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
* Implementation of docker model ConfigFile object
* @see <a href="https://github.com/docker/docker/blob/v1.6.0/registry/auth.go#L37">source</a>
* @author Max Shaposhnik
*
*/
public class AuthConfigs {

private Map<String, AuthConfig> configs;
private String rootPath; // not yet used


public AuthConfigs() {
this.configs = new HashMap<>();
}

public void addConfig(AuthConfig authConfig) {
this.configs.put(authConfig.getServeraddress(), authConfig);
}

public Map<String, AuthConfig> getConfigs() {
return Collections.unmodifiableMap(configs);
}

//for json conversion
public void setConfigs(Map<String, AuthConfig> configs) {
this.configs = configs;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (c) 2012-2015 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.docker;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Structure;
import com.sun.jna.ptr.LongByReference;

import org.eclipse.che.api.core.util.SystemInfo;

import java.util.Arrays;
import java.util.List;

/**
* @author andrew00x
*/
// C language functions
public interface CLibrary extends Library {
int AF_UNIX = 1; // Defined in 'sys/socket.h'
int SOCK_STREAM = 1; // Defined in 'sys/socket.h'

// Defined in 'unix.h', see http://man7.org/linux/man-pages/man7/unix.7.html
public static class SockAddrUn extends Structure {
public static final int UNIX_PATH_MAX = 108;

public short sun_family;
public byte[] sun_path;

public SockAddrUn(String path) {
byte[] pathBytes = path.getBytes();
if (pathBytes.length > UNIX_PATH_MAX) {
throw new IllegalArgumentException(String.format("Path '%s' is too long. ", path));
}
sun_family = AF_UNIX;
sun_path = new byte[pathBytes.length + 1];
System.arraycopy(pathBytes, 0, sun_path, 0, Math.min(sun_path.length - 1, pathBytes.length));
allocateMemory();
}

@Override
protected List getFieldOrder() {
return Arrays.asList("sun_family", "sun_path");
}
}

int socket(int domain, int type, int protocol);

int connect(int fd, SockAddrUn sock_addr, int addr_len);

int send(int fd, byte[] buffer, int count, int flags);

int recv(int fd, byte[] buffer, int count, int flags);

int close(int fd);

String strerror(int errno);

int write(int fd, byte[] buff, int count);

int read(int fd, byte[] buf, int count);

int eventfd(int initval, int flag);

int eventfd_read(int fd, LongByReference val);

int open(String path, int mode);

int O_RDONLY = 0x00;
int O_WRONLY = 0x01;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2012-2015 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.docker;

import com.sun.jna.Native;

import org.eclipse.che.api.core.util.SystemInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author andrew00x
*/
public class CLibraryFactory {
private static final Logger LOG = LoggerFactory.getLogger(CLibraryFactory.class);

private static final CLibrary C_LIBRARY;

static {
CLibrary tmp = null;
if (SystemInfo.isLinux()) {
try {
tmp = ((CLibrary)Native.loadLibrary("c", CLibrary.class));
} catch (Exception e) {
LOG.error("Cannot load native library", e);
}
}
C_LIBRARY = tmp;
}

public static CLibrary getCLibrary() {
checkCLibrary();
return C_LIBRARY;
}

private static void checkCLibrary() {
if (C_LIBRARY == null) {
throw new IllegalStateException("Can't load native library. Not linux system?");
}
}

private CLibraryFactory() {
}
}
Loading