Skip to content

Commit

Permalink
[BEAM-2877][BEAM-2881] Add Java SDK harness container image and support
Browse files Browse the repository at this point in the history
 * Add support for building Go code and docker container images with
   maven (see sdks/go/BUILD.md for details). The latter is only done
   if the "build-containers" profile is used.
 * Add GCS proxy service for managing artifacts in GCS.
 * Add GCE md service for metdata-configured provision info in GCE.
 * Add beamctl tool for manually interacting with these services.

This PR is focused on the execution side and would need support from
the submission side as well to be functional. The ULR will likely be
the first runner to tie everything together. The contents of the java
image is kept simple for now.
  • Loading branch information
herohde committed Oct 4, 2017
1 parent 9379ca2 commit 5d669a8
Show file tree
Hide file tree
Showing 39 changed files with 4,205 additions and 1 deletion.
49 changes: 49 additions & 0 deletions pom.xml
Expand Up @@ -179,6 +179,9 @@
<kubectl>kubectl</kubectl>
<!-- the standard location for kubernete's config file -->
<kubeconfig>${user.home}/.kube/config</kubeconfig>

<!-- For container builds, override to push containers to a registry -->
<docker-repository-root>${user.name}</docker-repository-root>
</properties>

<packaging>pom</packaging>
Expand Down Expand Up @@ -363,6 +366,35 @@
</pluginManagement>
</build>
</profile>

<profile>
<id>build-containers</id>
<build>
<!-- TODO(BEAM-2878): enable container build for releases -->
<pluginManagement>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
<configuration>
<tag>latest</tag>
<noCache>true</noCache>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>

</profiles>

<dependencyManagement>
Expand Down Expand Up @@ -1848,6 +1880,23 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.igormaznitsa</groupId>
<artifactId>mvn-golang-wrapper</artifactId>
<version>2.1.6</version>
<extensions>true</extensions>
<configuration>
<goVersion>1.9</goVersion>
</configuration>
</plugin>

<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.5</version>
<!-- no executions by default. Use build-containers profile -->
</plugin>
</plugins>
</pluginManagement>

Expand Down
30 changes: 30 additions & 0 deletions runners/gcp/gcemd/Dockerfile
@@ -0,0 +1,30 @@
###############################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################

FROM debian:stretch
MAINTAINER "Apache Beam <dev@beam.apache.org>"

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates \
&& \
rm -rf /var/lib/apt/lists/*

ADD target/linux_amd64/gcemd /opt/apache/beam/

ENTRYPOINT ["/opt/apache/beam/gcemd"]
85 changes: 85 additions & 0 deletions runners/gcp/gcemd/main.go
@@ -0,0 +1,85 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// gcemd is a metadata-configured provisioning server for GCE.
package main

import (
"flag"
"log"
"net"

"cloud.google.com/go/compute/metadata"
pb "github.com/apache/beam/sdks/go/pkg/beam/model/org_apache_beam_fn_v1"
"github.com/apache/beam/sdks/go/pkg/beam/provision"
"golang.org/x/net/context"
"google.golang.org/grpc"
)

var (
endpoint = flag.String("endpoint", "", "Server endpoint to expose.")
)

func main() {
flag.Parse()
if *endpoint == "" {
log.Fatal("No endpoint provided. Use --endpoint=localhost:12345")
}
if !metadata.OnGCE() {
log.Fatal("Not running on GCE")
}

log.Printf("Starting provisioning server on %v", *endpoint)

jobID, err := metadata.InstanceAttributeValue("job_id")
if err != nil {
log.Fatalf("Failed to find job ID: %v", err)
}
jobName, err := metadata.InstanceAttributeValue("job_name")
if err != nil {
log.Fatalf("Failed to find job name: %v", err)
}
opt, err := metadata.InstanceAttributeValue("sdk_pipeline_options")
if err != nil {
log.Fatalf("Failed to find SDK pipeline options: %v", err)
}
options, err := provision.JSONToProto(opt)
if err != nil {
log.Fatalf("Failed to parse SDK pipeline options: %v", err)
}

info := &pb.ProvisionInfo{
JobId: jobID,
JobName: jobName,
PipelineOptions: options,
}

gs := grpc.NewServer()
pb.RegisterProvisionServiceServer(gs, &server{info: info})

listener, err := net.Listen("tcp", *endpoint)
if err != nil {
log.Fatalf("Failed to listen to %v: %v", *endpoint, err)
}
log.Fatalf("Server failed: %v", gs.Serve(listener))
}

type server struct {
info *pb.ProvisionInfo
}

func (s *server) GetProvisionInfo(ctx context.Context, req *pb.GetProvisionInfoRequest) (*pb.GetProvisionInfoResponse, error) {
return &pb.GetProvisionInfoResponse{Info: s.info}, nil
}
154 changes: 154 additions & 0 deletions runners/gcp/gcemd/pom.xml
@@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-gcp-parent</artifactId>
<version>2.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>beam-runners-gcp-gcemd</artifactId>

<packaging>pom</packaging>

<name>Apache Beam :: Runners :: Google Cloud Platform :: GCE metadata provisioning</name>

<properties>
<!-- Add full path directory structure for 'go get' compatibility -->
<go.source.base>${project.basedir}/target/src</go.source.base>
<go.source.dir>${go.source.base}/github.com/apache/beam/sdks/go</go.source.dir>
</properties>

<build>
<sourceDirectory>${go.source.base}</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-go-cmd-source</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${go.source.base}/github.com/apache/beam/cmd/gcemd</outputDirectory>
<resources>
<resource>
<directory>.</directory>
<includes>
<include>*.go</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<!-- CAVEAT: for latest shared files, run mvn install in sdks/go -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependency</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-go</artifactId>
<version>${project.version}</version>
<type>zip</type>
<classifier>pkg-sources</classifier>
<overWrite>true</overWrite>
<outputDirectory>${go.source.dir}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.igormaznitsa</groupId>
<artifactId>mvn-golang-wrapper</artifactId>
<executions>
<execution>
<id>go-get-imports</id>
<goals>
<goal>get</goal>
</goals>
<phase>compile</phase>
<configuration>
<packages>
<package>google.golang.org/grpc</package>
<package>golang.org/x/oauth2/google</package>
<package>cloud.google.com/go/compute/metadata</package>
</packages>
</configuration>
</execution>
<execution>
<id>go-build</id>
<goals>
<goal>build</goal>
</goals>
<phase>compile</phase>
<configuration>
<packages>
<package>github.com/apache/beam/cmd/gcemd</package>
</packages>
<resultName>gcemd</resultName>
</configuration>
</execution>
<execution>
<id>go-build-linux-amd64</id>
<goals>
<goal>build</goal>
</goals>
<phase>compile</phase>
<configuration>
<packages>
<package>github.com/apache/beam/cmd/gcemd</package>
</packages>
<resultName>linux_amd64/gcemd</resultName>
<targetArch>amd64</targetArch>
<targetOs>linux</targetOs>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<configuration>
<repository>${docker-repository-root}/gcemd</repository>
</configuration>
</plugin>
</plugins>
</build>
</project>
30 changes: 30 additions & 0 deletions runners/gcp/gcsproxy/Dockerfile
@@ -0,0 +1,30 @@
###############################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################

FROM debian:stretch
MAINTAINER "Apache Beam <dev@beam.apache.org>"

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates \
&& \
rm -rf /var/lib/apt/lists/*

ADD target/linux_amd64/gcsproxy /opt/apache/beam/

ENTRYPOINT ["/opt/apache/beam/gcsproxy"]

0 comments on commit 5d669a8

Please sign in to comment.