Skip to content

Commit

Permalink
Publishing GCP Marketplace Click to Deploy VM images source code! (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
wgrzelak authored Feb 26, 2019
1 parent 0f852bc commit 8b3ccb5
Show file tree
Hide file tree
Showing 615 changed files with 17,921 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See https://help.github.com/en/articles/about-code-owners
# for more info about CODEOWNERS file.

# GCB configuration.
cloudbuild-vm.yaml @wgrzelak @khajduczenia @huyhg
File renamed without changes.
56 changes: 56 additions & 0 deletions cloudbuild-vm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2018 Google LLC
#
# Licensed 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.
#
# The following variables are required to be provided:
#
# PROJECT_ID - <YOUR PROJECT ID>
# _SERVICE_ACCOUNT_JSON_GCS - gs://<GCS URL TO SERVICE ACCOUNT JSON KEY>
# _LOGS_BUCKET - <GCS BUCKET TO EXPORT PACKER LOGS>
# _SOLUTION_NAME - <VM IMAGE TO BE BUILT>

timeout: 1200s # 20m
options:
workerPool: 'cloud-marketplace-ops-test/gcb-workers-pool'
steps:

- id: Download Service Account Key
name: gcr.io/cloud-builders/gsutil
args:
- 'cp'
- '${_SERVICE_ACCOUNT_JSON_GCS}'
- 'service-account.json'

- id: Build VM-based Solution
name: gcr.io/cloud-builders/docker
waitFor:
- Download Service Account Key
args:
- 'run'
- '--env=PROJECT=${PROJECT_ID}'
- '--env=BUCKET=${_LOGS_BUCKET}'
- '--env=KEY_FILE_PATH=/service-account.json'
- '--env=CHEF_DIR=/chef'
- '--env=PACKER_DIR=/packer/templates'
- '--env=TESTS_DIR=/tests'
- '--env=SOLUTION_NAME=${_SOLUTION_NAME}'
- '--env=RUN_TESTS=true'
- '--env=ATTACH_LICENSE=true'
- '--env=LICENSE_PROJECT_NAME=click-to-deploy-images'
- '--env=USE_INTERNAL_IP=true'
- '--env=TESTS_CUSTOM_METADATA=google-c2d-startup-enable=0'
- '--volume=/workspace/vm/chef:/chef:ro'
- '--volume=/workspace/vm/packer:/packer:ro'
- '--volume=/workspace/vm/tests:/tests:ro'
- '--volume=/workspace/service-account.json:/service-account.json:ro'
- 'gcr.io/cloud-marketplace-tools/vm/imagebuilder:0.1.0'
192 changes: 192 additions & 0 deletions vm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# Google Click to Deploy Images

## About

This directory hosts the source code of Google Click to Deploy VM images available through Google Cloud Platform Marketplace.

## Disclaimer

This is not an officially supported Google product.

## Repository structure

* [chef](chef) directory:

Contains [Chef](https://www.chef.io/chef/) cookbooks that install
packages, tools and scripts, and configure the applications and
services running on the VM instances.

The cookbooks are designed for reuse, and several
of the solutions are built using more than one cookbook. For example, the
[Redmine](https://console.cloud.google.com/marketplace/details/click-to-deploy-images/redmine)
solution is built using the `apache` and `mysql` cookbooks, and
[Alfresco Community Edition](https://console.cloud.google.com/marketplace/details/click-to-deploy-images/alfresco)
uses the `openjdk8`, `apache` and `postgesql` cookbooks.

The [`c2d-config`](chef/cookbooks/c2d-config) cookbook is
used by all Click to Deploy Images solutions. It automatically
configures startup and utility scripts, installs useful packages,
and configures the swap space.

* [packer](packer) directory:

[Packer](https://www.packer.io/) is a tool for building VM images, based on
a wide range of available _provisioners_.

In Click to Deploy Images solutions, Packer is used to create VM
instances from a preset base OS image, using
[Google Compute Builder](https://www.packer.io/docs/builders/googlecompute.html),
and by running Chef cookbooks with
[Chef Solo Provisioner](https://www.packer.io/docs/provisioners/chef-solo.html).
The image is then configured using
[Shell Provisioner](https://www.packer.io/docs/provisioners/shell.html).

After you run the Packer build, the VM image is stored in your GCP
project.

* [tests](tests) directory:

There are two types of tests that are run against the newly-created images:

1. Bash scripts executed on each image and verifying coverage of common the
requirements, stored in [`tests/common`](tests/common).
1. Solution-specific tests run with [Serverspec](https://serverspec.org),
stored in [`tests/solutions`](tests/solutions).

## Build an image in a local environment

Use the following steps to build a Click to Deploy solution's VM image.

### Clone this repository

```
git clone https://github.com/GoogleCloudPlatform/click-to-deploy.git
cd click-to-deploy/vm
```

### Build a VM image using the container image

To build an image, use `imagebuilder`. For information on Imagebuilder,
see the [marketplace-vm-imagebuilder](https://github.com/GoogleCloudPlatform/marketplace-vm-imagebuilder)
repository.

To pull the `imagebuilder` container image, run the following `docker`
command:

```shell
docker pull gcr.io/cloud-marketplace-tools/vm/imagebuilder:0.1.0
```

The container uses a GCP service account JSON key to access the GCP project,
create VM instances, and save the VM image. For information
about creating and managing service account in GCP, see the GCP documentation
for
[Creating and managing service accounts](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
and
[Managing roles and permissions](https://cloud.google.com/iam/docs/granting-changing-revoking-access).

The rest of this guide assumes that the absolute path to the
service account key is stored in the `KEY_FILE_PATH` environment variable.

Set the environment variable for the absolute path to the service account key:

```shell
export KEY_FILE_PATH=<ABSOLUTE PATH FOR THE SERVICE ACCOUNT KEY>
```

Set the environment variables for the GCP project name, Google Cloud Storage (GCS)
bucket name, and solution to be built:

```shell
export PROJECT=<YOUR GCP PROJECT>
export BUCKET=<GCS BUCKET NAME TO STORE BUILD LOGS>
export SOLUTION_NAME=<VM IMAGE TO BE BUILT>
```

Now you can use the `imagebuilder` container to build the VM image:

```shell
docker run \
-v "$PWD/packer:/packer:ro" \
-v "$PWD/chef:/chef:ro" \
-v "$PWD/tests:/tests:ro" \
-v "$KEY_FILE_PATH:/service-account.json:ro" \
-e "PROJECT=$PROJECT" \
-e "BUCKET=$BUCKET" \
-e "SOLUTION_NAME=$SOLUTION_NAME" \
-e "RUN_TESTS=true" \
-e "ATTACH_LICENSE=true" \
-e "LICENSE_PROJECT_NAME=click-to-deploy-images" \
-e "TESTS_CUSTOM_METADATA=google-c2d-startup-enable=0" \
gcr.io/cloud-marketplace-tools/vm/imagebuilder:0.1.0
```

For more configuration options, see
[Volume mounts](https://github.com/GoogleCloudPlatform/marketplace-vm-imagebuilder/blob/master/README.md#volume-mounts)
and
[Environment variables](https://github.com/GoogleCloudPlatform/marketplace-vm-imagebuilder/blob/master/README.md#environment-variables).

## Cloud Build CI

This repository uses Cloud Build for continuous integration. The Cloud Build
configuration file is located at
[`../cloudbuild-vm.yaml`](../cloudbuild-vm.yaml).

### Manually run the build

Cloud Build can be triggered manually by running the following command from the
root directory of this repository:

```shell
export GCP_PROJECT_TO_RUN_CLOUD_BUILD=<YOUR PROJECT ID>
export PACKER_LOGS_GCS_BUCKET_NAME=<GCS BUCKET TO EXPORT PACKER LOGS>
export SERVICE_ACCOUNT_KEY_JSON_GCS=gs://<GCS URL TO SERVICE ACCOUNT JSON KEY>
export SOLUTION_NAME=<VM IMAGE TO BE BUILT>

gcloud builds submit . \
--config cloudbuild-vm.yaml \
--substitutions _LOGS_BUCKET=$PACKER_LOGS_GCS_BUCKET_NAME,_SERVICE_ACCOUNT_JSON_GCS=$SERVICE_ACCOUNT_KEY_JSON_GCS,_SOLUTION_NAME=$SOLUTION_NAME \
--project $GCP_PROJECT_TO_RUN_CLOUD_BUILD
```

### Build steps

1. The service account JSON key is downloaded from the GCS bucket to
Cloud Build's workspace.

1. After the above step is executed successfully, the `imagebuilder` container runs and builds
the VM image defined in the `$_SOLUTION_NAME` variable.

### GCB custom worker pools

To allow connection via an internal IP. The Cloud Build configuration uses
Google Cloud Build (GCB) custom worker pools.

If you want to create a new worker pool, run the following command:

```shell
gcloud alpha builds worker-pools create gcb-workers-pool \
--project=[PROJECT_ID] \
--regions=us-central1,us-west1,us-east1,us-east-4 \
--worker-count=2 \
--worker-machine-type=n1-standard-1 \
--worker-tag=gcb-worker \
--worker-network-name=default \
--worker-network-project=[PROJECT_ID] \
--worker-network-subnet=default
```

Where:

* `[PROJECT_ID]` is the GCP project ID where you want to create your custom worker pool.

If you want to update the number of workers in an existing pool, run the following command:

```shell
gcloud alpha builds worker-pools update gcb-workers-pool \
--project=[PROJECT_ID] \
--worker-count=4 \
```

For more information, see the
[gcloud alpha builds worker-pools commands](https://cloud.google.com/sdk/gcloud/reference/alpha/builds/worker-pools/).
102 changes: 102 additions & 0 deletions vm/chef/chefignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Put files/directories that should be ignored in this file when uploading
# to a chef-server or supermarket.
# Lines that start with '# ' are comments.

# OS generated files #
######################
.DS_Store
Icon?
nohup.out
ehthumbs.db
Thumbs.db

# SASS #
########
.sass-cache

# EDITORS #
###########
\#*
.#*
*~
*.sw[a-z]
*.bak
REVISION
TAGS*
tmtags
*_flymake.*
*_flymake
*.tmproj
.project
.settings
mkmf.log

## COMPILED ##
##############
a.out
*.o
*.pyc
*.so
*.com
*.class
*.dll
*.exe
*/rdoc/

# Testing #
###########
.watchr
.rspec
spec/*
spec/fixtures/*
test/*
features/*
examples/*
Guardfile
Procfile
.kitchen*
.rubocop.yml
spec/*
Rakefile
.travis.yml
.foodcritic
.codeclimate.yml

# SCM #
#######
.git
*/.git
.gitignore
.gitmodules
.gitconfig
.gitattributes
.svn
*/.bzr/*
*/.hg/*
*/.svn/*

# Berkshelf #
#############
Berksfile
Berksfile.lock
cookbooks/*
tmp

# Cookbooks #
#############
CONTRIBUTING*
CHANGELOG*
TESTING*
MAINTAINERS.toml

# Strainer #
############
Colanderfile
Strainerfile
.colander
.strainer

# Vagrant #
###########
.vagrant
Vagrantfile
37 changes: 37 additions & 0 deletions vm/chef/cookbooks/alfresco/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2018 Google LLC
#
# Licensed 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.

default['alfresco']['install']['url'] = 'https://download.alfresco.com/release/community/201707-build-00028/alfresco-community-installer-201707-linux-x64.bin'
default['alfresco']['install']['sha256'] = '099d2f26c593e58fe640e714e561d317b8ad3458bd361020796ed79a41a4f259'

default['alfresco']['db']['username'] = 'alfresco'
default['alfresco']['db']['password'] = 'alfresco'
default['alfresco']['db']['name'] = 'alfresco'

default['alfresco']['src']['temp_packages'] = ['subversion', 'git']

# Downloading jmagick and jodconverter from fork,
# because original repositories are no longer available
default['alfresco']['src']['urls'] = {
'alfresco_svn' => 'https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/COMMUNITYTAGS/5.2.f/root',

'gytheio_git' => 'git://github.com/Alfresco/gytheio.git',
'jmagick_git' => 'git://github.com/techblue/jmagick.git',
'jodconverter_git' => 'git://github.com/mirkonasato/jodconverter.git',

'hibernate_wget' => 'https://downloads.sourceforge.net/project/hibernate/hibernate3/3.2.6.ga/hibernate-3.2.6.ga.tar.gz',
'java_geom_wget' => 'https://downloads.sourceforge.net/project/geom-java/javaGeom/javaGeom-0.11.2/javaGeom-0.11.2-src.zip',
'jid3lib_wget' => 'https://downloads.sourceforge.net/project/javamusictag/jid3lib/beta-dev6/jid3lib-0.5.4.tar.gz',
'libwmf_wget' => 'https://sourceforge.net/projects/wvware/files/libwmf/0.2.8.4/libwmf-0.2.8.4.tar.gz'
}
Loading

0 comments on commit 8b3ccb5

Please sign in to comment.