{"id":101,"date":"2023-01-23T11:01:38","date_gmt":"2023-01-23T11:01:38","guid":{"rendered":"https:\/\/keyshell.net\/blog\/?p=101"},"modified":"2023-01-23T11:01:38","modified_gmt":"2023-01-23T11:01:38","slug":"how-to-integrate-google-cloud-build-with-jfrog-artifactory","status":"publish","type":"post","link":"https:\/\/keyshell.net\/blog\/2023\/01\/23\/how-to-integrate-google-cloud-build-with-jfrog-artifactory\/","title":{"rendered":"How to Integrate Google Cloud Build with JFrog Artifactory"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">In this blog we describe how to Integrate Google Cloud Build with Jfrog Artifactory.We will build a sample containerized application that pulls dependencies from Artifactory, with Maven and Java as our sample package and language.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">JFrog is a software company that provides a platform for managing and distributing software artifacts. The company&#8217;s main product, JFrog Artifactory, is a universal artifact repository that supports all major packaging formats, including Docker, Maven, npm, and NuGet. JFrog also offers other tools such as JFrog Xray and JFrog Mission Control for managing and monitoring software artifacts across an organization.<\/span><\/p>\n<p><b>What is an Artifact ?<\/b><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">An artifact is a by-product of software development. It\u2019s anything that is created so a piece of software can be developed. This might include things like data models, diagrams, setup scripts etc.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u201cArtifact\u201d is a pretty broad term when it comes to software development. Most pieces of software have a lot of artifacts that are necessary for them to run. Some artifacts explain how a piece of software is supposed to work, while others actually allow that program to run.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Artifacts are important to hold onto throughout the development process of any piece of software, and even long after.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Without each and every artifact, it can make developing a piece of software much more difficult over time. This is especially true if development switches hands. When a new developer is put on a project, one of the first things they\u2019ll want to do is go through the artifacts to get an idea of how the software works.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If an artifact is missing, that leaves a developer in the dark. This is why most artifacts are kept in a repository. This lets relevant developers access the artifacts at any time, all from one place.<\/span><\/p>\n<p><b>What is Artifactory ?<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Artifactory is Jfrog\u2019s tool which acts as an artifact repository.It\u2019s a place to store all your Binaries,Builds &amp; Metadata.<\/span><\/p>\n<p><b><i>Prerequisites:<\/i><\/b><b><i><br \/>\n<\/i><\/b><i><span style=\"font-weight: 400;\">Google Cloud Account : Should Enable Google Cloud Build<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">JFrog Account :We used 30 days trial from Google Cloud\u2019s MarketPlace (<\/span><\/i><a href=\"https:\/\/console.cloud.google.com\/marketplace\/product\/jfrog\/jfrog-pro-team-saas\"><i><span style=\"font-weight: 400;\">https:\/\/console.cloud.google.com\/marketplace\/product\/jfrog\/jfrog-pro-team-saas<\/span><\/i><\/a><i><span style=\"font-weight: 400;\">)<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">First,Let\u2019s Install and Setup Google Cloud CLI.We are using Ubuntu 20.04 LTS (Debian).You can skip this step if you have source code in <\/span><i><span style=\"font-weight: 400;\">Google Cloud Shell<\/span><\/i><span style=\"font-weight: 400;\"> and edit using <\/span><i><span style=\"font-weight: 400;\">Google Cloud Editor<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1)To download the Linux 64-bit archive file, at the command line, run:<\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$ curl -O https:\/\/dl.google.com\/dl\/cloudsdk\/channels\/rapid\/downloads\/google-cloud-cli-413.0.0-linux-x86_64.tar.gz<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">2)Extract the contents of the file to any location on your file system (preferably your Home directory)<\/span><\/p>\n<blockquote><p><em>$ tar -xf google-cloud-cli-413.0.0-linux-x86.tar.gz<\/em><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">3)Run the installation script from the root of the folder you extracted to using the following command:<\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$ .\/google-cloud-sdk\/install.sh<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">4)<\/span><span style=\"font-weight: 400;\">To initialize the gcloud CLI, run:<\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$ .\/google-cloud-sdk\/bin\/gcloud init<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">5)After initialize,add to path :<\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$ export PATH=$PATH:\/home\/user\/google-cloud-sdk\/bin<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">After this we can run gcloud CLI commands directly.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">Eg :<\/span> <i><span style=\"font-weight: 400;\">$ gcloud info<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">For reference for setting up Google Cloud CLI refer : <\/span><a href=\"https:\/\/cloud.google.com\/sdk\/docs\/install-sdk#linux\"><span style=\"font-weight: 400;\">https:\/\/cloud.google.com\/sdk\/docs\/install-sdk#linux<\/span><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Next,we can clone the source code from github.<\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$ git clone https:\/\/github.com\/Keyshelltechs\/Keyshell_Jfrog.git<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">Folder Structure :\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\ud83d\udcc1examples<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\ud83d\udcc3DockerFile<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\ud83d\udcc3cloudbuild.yaml<\/span><\/p>\n<p><span style=\"font-weight: 400;\">First we have to build a Maven Image that includes JFrog CLI. For that we can use <\/span><i><span style=\"font-weight: 400;\">cloudbuild.yaml<\/span><\/i><span style=\"font-weight: 400;\"> and <\/span><i><span style=\"font-weight: 400;\">DockerFile<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Snippet of <\/span><i><span style=\"font-weight: 400;\">cloudbuild.yaml <\/span><\/i><\/p>\n<pre><code>- name: 'gcr.io\/cloud-builders\/docker'\r\n  args:\r\n  - 'build'\r\n  - '--build-arg=BASE_IMAGE=gcr.io\/cloud-builders\/mvn:3.5.0-jdk-8'  \r\n  - '--tag=gcr.io\/$PROJECT_ID\/java\/jfrog:1.54.1'\r\n  - '.'\r\n  wait_for: ['-']<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">gcr.io\/cloud-builders is a public container registry.<\/span><br \/>\n<span style=\"font-weight: 400;\">Here we use an image of Maven(<\/span><i><span style=\"font-weight: 400;\">mvn:3.5.0-jdk-8<\/span><\/i><span style=\"font-weight: 400;\">) from gcr.io\/cloud-builders as base image to build Maven Image including JFrog CLI.You can see the image <a href=\"https:\/\/console.cloud.google.com\/gcr\/images\/cloud-builders\/global\/mvn@sha256:897bbdeab097c9a599c47da89e336113a3fe00a6418a5cd2672504a866b46a24\/details?tab=vulnz%20:mvn%20image%20:3.5.0\">here<\/a>.<br \/>\n<i>DockerFile<\/i><\/span><\/p>\n<pre><code>ARG BASE_IMAGE=gcr.io\/${PROJECT_ID}\/mvn:3.5.0-jdk-8\r\nFROM ${BASE_IMAGE}\r\n\r\nARG JFROG_CLI_VERSION=1.54.1\r\n\r\n# PR submitted to download versioned JFrog CLI\r\n\r\nRUN apt-get update -qqy &amp;&amp; apt-get install -qqy curl \\\r\n  &amp;&amp; cd \/tmp \\\r\n  &amp;&amp; curl -fL https:\/\/getcli.jfrog.io | sh \\\r\n  &amp;&amp; mv jfrog \/usr\/bin\/ \\\r\n  &amp;&amp; apt-get remove -qqy --purge curl \\\r\n  &amp;&amp; rm \/var\/lib\/apt\/lists\/*_*\r\n\r\nENTRYPOINT [\"jfrog\"]<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">Here we use this DockerFile to build the final image by adding JFrog CLI to the base image.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So the final image will be tagged as <\/span><i><span style=\"font-weight: 400;\">gcr.io\/$PROJECT_ID\/java\/jfrog:1.54.1<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Now let\u2019s build this image using Google Cloud Shell\/Google Cloud CLI.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To build using Google Cloud Shell use this command : <\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$ gcloud builds submit &#8211;config=cloudbuild.yaml &#8211;project=your_google_project_id .<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">To build using Google Cloud CLI use this command : <\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$ gcloud builds submit &#8211;config=cloudbuild.yaml .<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">If the build is successful we can view the image in your GCP\u2019s container registry.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Container Registry &gt; Images &gt; Java &gt; JFrog<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To check build results navigate to Cloud Build &gt; History<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now we have built a Maven Image that includes JFrog CLI.We have to configure it to point it to Jfrog Artifactory.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For that first we have to create a <\/span><i><span style=\"font-weight: 400;\">Virtual Snapshot Repository<\/span><\/i><span style=\"font-weight: 400;\"> and a <\/span><i><span style=\"font-weight: 400;\">Virtual Release Repository <\/span><\/i><span style=\"font-weight: 400;\">in Jfrog.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For creating these we have to login to our Jfrog Account.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">After Logging in, let\u2019s take a look on how we can create a <\/span><i><span style=\"font-weight: 400;\">Virtual Release Repository.<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">For creating a Virtual Repository , first we have to create a local and remote repository.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Before that let\u2019s check what a local,remote and virtual repository is.<\/span><\/p>\n<p><b>Local Repository:<\/b><span style=\"font-weight: 400;\"> In JFrog, a local repository is a repository that is stored on the same machine as the JFrog Artifactory instance. It functions as a cache of all the artifacts that have been downloaded from remote repositories, and as a target for deploying artifacts that have been built locally.The local repository allows for faster access to frequently used artifacts and can also be used to manage internal artifacts that should not be exposed to external systems.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Remote Repository: <\/b><span style=\"font-weight: 400;\">In JFrog, a remote repository is a repository that is stored on a different machine or in a different location than the JFrog Artifactory instance. It generally refers to external repositories from where the artifacts are downloaded. A remote repository can be located in a different Artifactory server, or it can be a repository hosted by a third-party provider, such as Maven Central or JCenter. Remote repositories provide a way to access external artifacts that are needed for a build, and to share artifacts that have been deployed to Artifactory with other teams or systems. When a client requests an artifact that is not present in any of its local repositories, Artifactory will check the remote repositories in the order they are defined in the system, and will download the artifact from the first repository that contains it.<\/span><\/p>\n<p><b>Virtual Repository: <\/b><span style=\"font-weight: 400;\">In JFrog, a virtual repository is a virtual aggregation of multiple local, remote and other virtual repositories. It allows you to access all of your repositories as if they were a single, unified repository. This makes it easy to manage and access multiple repositories from a single URL, and it also allows you to easily switch between different sets of repositories depending on your needs.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, you can use a virtual repository to aggregate all of your local, remote and other virtual repositories into a single URL, and then use that URL as the repository in your build tool&#8217;s configuration. This allows you to switch between different sets of repositories without changing your build configuration. Additionally, it allows you to manage access and permissions for a group of repositories together, and also search for artifacts across all repositories in the virtual repository.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Virtual repositories can be very useful to organize your artifacts and make it easier to manage access and permissions for different projects, teams or environments.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Now let\u2019s create Local,Remote and Virtual Repository<\/span><\/p>\n<p><strong><span style=\"text-decoration: underline;\">To create Local Repository :\u00a0<\/span><\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Select Administration &gt; Repositories &gt; Repositories &gt; Add Repositories &gt; Local Repository<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Then select \u201cMaven\u201d as Package Type.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"my-custom-class\" src=\"https:\/\/keyshell.net\/blog\/wp-content\/uploads\/2023\/01\/1-Repository-Screen.png\" alt=\"\" width=\"1920\" height=\"1004\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Add \u201ckeyshell-maven-local\u201d as Repository Key and click on \u201cCreate Local Repository\u201d<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"my-custom-class\" src=\"https:\/\/keyshell.net\/blog\/wp-content\/uploads\/2023\/01\/2-Create-Local-Repo.png\" alt=\"\" width=\"1920\" height=\"982\" \/><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>To create Remote Repository :\u00a0<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Select Administration &gt; Repositories &gt; Repositories &gt; Add Repositories &gt; Remote Repository<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Then select \u201cMaven\u201d as Package Type.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Add \u201ckeyshell-maven-remote\u201d as Repository Key.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Add \u201c<\/span><a href=\"https:\/\/jcenter.bintray.com\"><span style=\"font-weight: 400;\">https:\/\/jcenter.bintray.com<\/span><\/a><span style=\"font-weight: 400;\">\u201d as URL. (JCenter is a public, Bintray-hosted repository that is used to store and distribute Java and Android libraries. JCenter is maintained by JFrog)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now click on \u201cCreate Remote Repository\u201d<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"my-custom-class\" src=\"https:\/\/keyshell.net\/blog\/wp-content\/uploads\/2023\/01\/3-Create-Remote-Repo.png\" alt=\"\" width=\"1909\" height=\"989\" \/><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>To create Virtual Repository :\u00a0<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Select Administration &gt; Repositories &gt; Repositories &gt; Add Repositories &gt; Virtual Repository<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Then select \u201cMaven\u201d as Package Type.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Add \u201ckeyshell-maven-virtual\u201d as Repository Key.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"my-custom-class\" src=\"https:\/\/keyshell.net\/blog\/wp-content\/uploads\/2023\/01\/4a-Create-Virtual-Repo.png\" alt=\"\" width=\"1920\" height=\"997\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Here we have the option to select from our local,remote and other virtual repositories.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now select \u201ckeyshell-maven-local\u201d and \u201ckeyshell-maven-remote\u201d from the list in the same order.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Also select \u201ckeyshell-maven-local\u201d as Default Deployment Repository.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now click on \u201cCreate Virtual Repository\u201d.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"my-custom-class\" src=\"https:\/\/keyshell.net\/blog\/wp-content\/uploads\/2023\/01\/4b-Create-Virtual-Repo-Select-Repo.png\" alt=\"\" width=\"1917\" height=\"1000\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Now we have created a <\/span><i><span style=\"font-weight: 400;\">Virtual Release Repository <\/span><\/i><span style=\"font-weight: 400;\">in Jfrog.Repeat the same steps to create <\/span><i><span style=\"font-weight: 400;\">Virtual Snapshot Repository.<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Now let\u2019s go inside our \u201cexamples\u201d folder.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"my-custom-class-example\" src=\"https:\/\/keyshell.net\/blog\/wp-content\/uploads\/2023\/01\/8-Examples.png\" alt=\"\" width=\"249\" height=\"205\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Here cloudbuild.yaml file is used to Configure JFrog CLI to point to JFrog Artifactory,Build a sample maven project and then containerize java app.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Snippet of <\/span><i><span style=\"font-weight: 400;\">cloudbuild.yaml<\/span><\/i><\/p>\n<pre><code><span style=\"font-weight: 400;\"># Configure JFrog CLI to point to JFrog Artifactory<\/span>\r\n\r\n<span style=\"font-weight: 400;\">- <\/span><span style=\"font-weight: 400;\">name<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">'docker.bintray.io\/google-cloud-builder\/java\/jfrog:0.1'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">entrypoint<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">'bash'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">args<\/span><span style=\"font-weight: 400;\">: [<\/span><span style=\"font-weight: 400;\">'-c'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'jfrog rt c rt-mvn-repo --url=https:\/\/[ARTIFACTORY-URL]\/artifactory --user=[ARTIFACTORY-USER] --password=[ARTIFACTORY-PASSWORD OR ARTIFACTORY IDENTITY TOKEN]'<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">dir<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">'maven-example'<\/span>\r\n\r\n<span style=\"font-weight: 400;\"># Build a sample maven project<\/span>\r\n\r\n<span style=\"font-weight: 400;\">- <\/span><span style=\"font-weight: 400;\">name<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">'gcr.io\/$PROJECT_ID\/java\/jfrog'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">args<\/span><span style=\"font-weight: 400;\">: [<\/span><span style=\"font-weight: 400;\">'rt'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'mvn'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\"clean install\"<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'config.yaml'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'--build-name=mybuild'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'--build-number=$BUILD_ID'<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">dir<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">'maven-example'<\/span>\r\n\r\n<span style=\"font-weight: 400;\"># Containerize java app<\/span>\r\n\r\n<span style=\"font-weight: 400;\">- <\/span><span style=\"font-weight: 400;\">name<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">'gcr.io\/cloud-builders\/docker'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">args<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0- <\/span><span style=\"font-weight: 400;\">'build'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0- <\/span><span style=\"font-weight: 400;\">'--tag=gcr.io\/$PROJECT_ID\/java-app:${BUILD_ID}'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0- <\/span><span style=\"font-weight: 400;\">'.'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">dir<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">'maven-example'<\/span><\/code><\/pre>\n<p><span style=\"font-weight: 400;\">Here <\/span><i><span style=\"font-weight: 400;\">docker.bintray.io\/google-cloud-builder\/java\/jfrog:0.1 <\/span><\/i><span style=\"font-weight: 400;\">is Jfrog Artifactory image which is used to Configure JFrog CLI to point to the JFrog Artifactory.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We have to update this cloudbuild.yaml with actual values of <\/span><b>[ARTIFACTORY-USER]<\/b><span style=\"font-weight: 400;\">,<\/span><b> [ARTIFACTORY-URL]<\/b><span style=\"font-weight: 400;\"> and <\/span><b>[ARTIFACTORY-PASSWORD OR ARTIFACTORY IDENTITY TOKEN]<\/b><\/p>\n<p><b>ARTIFACTORY IDENTITY TOKEN<\/b><span style=\"font-weight: 400;\"> can be generated after logging to Jfrog.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">(Click on the user button on top right corner &gt; Edit Profile &gt; Unlock &gt; Generate Identity Token)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The files required to build a sample maven project is under the \u201cmaven-example\u201d folder.We have to edit the \u201cconfig.yaml\u201d file in this directory.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">config.yaml<\/span><\/p>\n<pre><code><span style=\"font-weight: 400;\">version<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">1<\/span>\r\n\r\n<span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">maven<\/span>\r\n\r\n<span style=\"font-weight: 400;\">resolver<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">snapshotRepo<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">keyshell-snapshot-virtual<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">releaseRepo<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">keyshell-maven-virtual<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">serverID<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">rt-mvn-repo<\/span>\r\n\r\n<span style=\"font-weight: 400;\">deployer<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">snapshotRepo<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">keyshell-snapshot-virtual<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">releaseRepo<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">keyshell-maven-virtual<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">serverID<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">rt-mvn-repo<\/span><\/code><\/pre>\n<p><span style=\"font-weight: 400;\">Update the values of <\/span><i><span style=\"font-weight: 400;\">snapshotRepo<\/span><\/i><span style=\"font-weight: 400;\"> and <\/span><i><span style=\"font-weight: 400;\">releaseRepo <\/span><\/i><span style=\"font-weight: 400;\">with the Jfrog\u2019s virtual repositories which we have created earlier.<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">Dockerfile<\/span><\/i><span style=\"font-weight: 400;\"> in this directory is used to containerize the java app.<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">pom.xml<\/span><\/i><span style=\"font-weight: 400;\"> file is used in Apache Maven-based Java projects.It includes information such as the project&#8217;s dependencies on other libraries, the build plugins that should be used, and the project&#8217;s version number. This file is used by Maven to build and manage the project.<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">src <\/span><\/i><span style=\"font-weight: 400;\">directory contains the java program to display \u201cHello World\u201d.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now let\u2019s build this cloudbuild.yaml (inside examples folder) using Google Cloud Shell\/Google Cloud CLI.<\/span><br \/>\n<span style=\"font-weight: 400;\">To build using Google Cloud Shell use this command :<\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$ gcloud builds submit &#8211;config=cloudbuild.yaml &#8211;project=your_google_project_id .<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">To build using Google Cloud CLI use this command :<\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$ gcloud builds submit &#8211;config=cloudbuild.yaml .<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">If the build is successful we can view the image in your GCP\u2019s container registry.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Container Registry &gt; Images &gt; java-app<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To check build results navigate to Cloud Build &gt; History<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Once the app is containerized, it can be deployed on GKE or any other compute target.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">We can view the Artifacts in Jfrog.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Application &gt; Artifactory&gt; Artifacts<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"my-custom-class\" src=\"https:\/\/keyshell.net\/blog\/wp-content\/uploads\/2023\/01\/5-Artifacts.png\" alt=\"\" width=\"1920\" height=\"558\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Now we can run the containerized java app from GCP.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Container Registry &gt; Images &gt; java-app &gt; Select Image &gt; Show Pull Command<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"my-custom-class\" src=\"https:\/\/keyshell.net\/blog\/wp-content\/uploads\/2023\/01\/6-GCP-Pull.png\" alt=\"\" width=\"1914\" height=\"505\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Let\u2019s try running our container image in a cloud shell \/ VM .<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For that we can use these docker commands.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">To pull docker image of our containerized java app from the registry<\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$ docker pull your_image_name<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">To view the images<\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$docker images<\/span><\/i><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">To run the container<\/span><\/p>\n<blockquote><p><i><span style=\"font-weight: 400;\">$docker run -it image_name<\/span><\/i><\/p><\/blockquote>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"my-custom-class\" src=\"https:\/\/keyshell.net\/blog\/wp-content\/uploads\/2023\/01\/7-Hello-World-Output.png\" alt=\"\" width=\"1086\" height=\"484\" \/><\/p>\n<p><span style=\"font-weight: 400;\">\u201cHello World!\u201d is our expected output.<\/span><\/p>\n<p>If you have any queries contact us at <span style=\"font-weight: 400;\">\ud83d\udcf2 +91-81295 71359 or email us at support@keyshell.net<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog we describe how to Integrate Google Cloud Build with Jfrog Artifactory.We will build a sample containerized application that pulls dependencies from Artifactory, with Maven and Java as our sample package and language. JFrog is a software company that provides a platform for managing and distributing software artifacts. The company&#8217;s main product, JFrog [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/keyshell.net\/blog\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/keyshell.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/keyshell.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/keyshell.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/keyshell.net\/blog\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":64,"href":"https:\/\/keyshell.net\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":288,"href":"https:\/\/keyshell.net\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions\/288"}],"wp:attachment":[{"href":"https:\/\/keyshell.net\/blog\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/keyshell.net\/blog\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/keyshell.net\/blog\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}