# Scan Java packages automatically

Learn how to enable automatic scanning, push a container image on Artifact Registry,
and see a list of any vulnerabilities found in the image.

Artifact Analysis scans for vulnerabilities each time an image is
pushed to Artifact Registry. Platform administrators and application developers can
use this automatic scanning feature to help identify risks in their software
delivery pipeline.

This quickstart uses a simple publicly available package to demonstrate one type
of package scanning. By default, Artifact Analysis scans for
vulnerabilities in multiple package types once you enable the scanning API.
Supported package types include: OS, Go, Java (Maven), Python and Node.js (npm).

## Before you begin

> [!IMPORTANT]
> **Important:** When you enable the Artifact Analysis API, Artifact Analysis automatically begins scanning each new image as they are pushed to Artifact Registry repositories in your project. However, scanning is disabled by default for packages pushed to Artifact Registry repositories. To enable scanning in a repository, see [Control scanning settings for an individual repository](https://docs.cloud.google.com/artifact-analysis/docs/enable-automatic-scanning#disable-repo).

## Create a Docker repository in Artifact Registry

Create a Docker repository to store the sample image for this quickstart.

1. Open the **Repositories** page in the Google Cloud console.

   [Open the Repositories page](https://console.cloud.google.com/artifacts)
2. Click **Create Repository**.

3. On the **Create Repository** page, input the following settings:

   - **Name** : `quickstart-docker-repo`
   - **Format**: Docker
   - **Mode**: Standard
   - **Location type**: Region
   - **Region** : `us-central1`
4. Click **Create**.

You see the **Repositories** page. Your `quickstart-docker-repo` repository is added to the repository list.

## Configure authentication

Before you can push or pull images with Artifact Registry, you must configure Docker to use the Google Cloud CLI to authenticate requests to Artifact Registry.

In the Cloud Shell or your local shell, set up authentication for Docker repositories in the region `us-central1`:

    gcloud auth configure-docker us-central1-docker.pkg.dev

## Obtain a package

1. Change to a directory where you want to save your container image.

2. Copy an image into your local directory. For example, you can use Docker to pull the latest Jenkins image from [Docker Hub](https://hub.docker.com/_/jenkins).

       docker pull jenkins:2.60.3-alpine

## Tag your package with a repository name

When you want to push a package to Artifact Registry, you need to configure the `docker push` command to push the image to a specific location.

Run the following command to tag the image as `quickstart-image:tag1`:

```bash
docker tag jenkins:2.60.3-alpine \
us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1
```

Where

- <var translate="no">PROJECT</var> is your Google Cloud [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects). If your project ID contains a colon (`:`), see [Domain-scoped projects](https://docs.cloud.google.com/artifact-registry/docs/docker/names#domain).
- `us-central1` is the Artifact Registry repository region.
- `docker.pkg.dev` is the hostname for Docker repositories.
- `quickstart-image` is the image name you want to use in the repository. The image name can be different than the local image name.
- `tag1` is a tag you're adding to the Docker image. If you didn't specify a tag, Docker will apply the default tag `latest`.

## Push the image to Artifact Registry

Artifact Analysis automatically scans new images when they're uploaded to
Artifact Registry.

To push the image to your Docker repository in Artifact Registry, run the following command:

```bash
docker push us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1
```

Replace <var translate="no">PROJECT</var> with your Google Cloud
[project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects).
If your project ID contains a colon (`:`), see
[Domain-scoped projects](https://docs.cloud.google.com/artifact-registry/docs/docker/names#domain).

## View vulnerability scanning results

## Clean up


To avoid incurring charges to your Google Cloud account for
the resources used on this page, delete the Google Cloud project with the
resources.
If you created a new project for this guide, you can now delete the project.

<br />

> [!CAUTION]
> **Caution** : Deleting a project has the following effects:
>
> - **Everything in the project is deleted.** If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.
> - **Custom project IDs are lost.** When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as an `appspot.com` URL, delete selected resources inside the project instead of deleting the whole project.
>
>
> If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects
> can help you avoid exceeding project quota limits.

1. In the Google Cloud console, go to the **Manage resources** page.

   [Go to Manage resources](https://console.cloud.google.com/iam-admin/projects)
2. In the project list, select the project that you want to delete, and then click **Delete**.
3. In the dialog, type the project ID, and then click **Shut down** to delete the project.

## What's next

- [Explore on-demand scanning options](https://docs.cloud.google.com/artifact-analysis/docs/on-demand-scanning-howto).
- [Understand container scanning concepts](https://docs.cloud.google.com/artifact-analysis/docs/artifact-analysis).