Skip to content

Commit

Permalink
Fixing docker image and adding tf files (#75)
Browse files Browse the repository at this point in the history
* added terraform files

* changed name variable

* removed unneeded pip installations in the docker image

* fixed docker image pip installation

* updated changelog
  • Loading branch information
kessler-frost authored Nov 3, 2023
1 parent 3f708bf commit 9cb1fa4
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,13 @@ ipython_config.py

# Coverage
.coverage

# Terraform
**/.terraform/**
**/*.tfstate*
**/.terraform.lock.hcl
**/*.tfvars
**/*.plan

# Scratch
*.ipynb
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED]

### Added

- Added terraform files to the repo for deploying necessary resources

### Changed

- Removed the `--use-feature=in-tree-build` flag from the `pip install` command in the Dockerfile as it was causing the build to fail

## [0.27.0] - 2023-09-20

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir --use-feature=in-tree-build --upgrade \
RUN pip install --no-cache-dir --upgrade \
amazon-braket-pennylane-plugin==1.6.9 \
boto3==1.20.48 \
pennylane==0.24.0 \
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include VERSION
include requirements.txt
recursive-include covalent_braket_plugin/assets/infra/ *
59 changes: 59 additions & 0 deletions covalent_braket_plugin/assets/infra/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2023 Agnostiq Inc.
#
# This file is part of Covalent.
#
# Licensed under the Apache License 2.0 (the "License"). A copy of the
# License may be obtained with this software package or at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Use of this file is prohibited except in compliance with the License.
# 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.

provider "aws" {
region = var.aws_region
}

data "aws_caller_identity" "current" {}

# The bucket name needs amazon-braket prefix to be able to use the braket service.
resource "aws_s3_bucket" "braket_bucket" {
bucket = "amazon-braket-${var.name}-bucket"
force_destroy = true
}

resource "aws_ecr_repository" "braket_ecr_repo" {
name = "${var.name}-base-executor-repo"
image_tag_mutability = "MUTABLE"

force_delete = true
image_scanning_configuration {
scan_on_push = false
}

provisioner "local-exec" {
command = "docker pull public.ecr.aws/covalent/covalent-braket-executor:${var.executor_base_image_tag_name} && aws ecr get-login-password --region ${var.aws_region} | docker login --username AWS --password-stdin ${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.aws_region}.amazonaws.com && docker tag public.ecr.aws/covalent/covalent-braket-executor:${var.executor_base_image_tag_name} ${aws_ecr_repository.braket_ecr_repo.repository_url}:${var.executor_base_image_tag_name} && docker push ${aws_ecr_repository.braket_ecr_repo.repository_url}:${var.executor_base_image_tag_name}"
}
}

resource "aws_iam_role" "braket_iam_role" {
name = "${var.name}-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "braket.amazonaws.com"
}
},
]
})
managed_policy_arns = ["arn:aws:iam::aws:policy/AmazonBraketFullAccess"]
}
30 changes: 30 additions & 0 deletions covalent_braket_plugin/assets/infra/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2023 Agnostiq Inc.
#
# This file is part of Covalent.
#
# Licensed under the Apache License 2.0 (the "License"). A copy of the
# License may be obtained with this software package or at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Use of this file is prohibited except in compliance with the License.
# 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.

output "braket_job_execution_role_name" {
value = aws_iam_role.braket_iam_role.id
description = "Allocated IAM role name"
}

output "s3_bucket_name" {
value = aws_s3_bucket.braket_bucket.id
description = "Allocated AWS S3 bucket name for storing lambda files"
}

output "ecr_image_uri" {
value = "${aws_ecr_repository.braket_ecr_repo.repository_url}:${var.executor_base_image_tag_name}"
description = "Allocated ECR repo name"
}
31 changes: 31 additions & 0 deletions covalent_braket_plugin/assets/infra/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2023 Agnostiq Inc.
#
# This file is part of Covalent.
#
# Licensed under the Apache License 2.0 (the "License"). A copy of the
# License may be obtained with this software package or at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Use of this file is prohibited except in compliance with the License.
# 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.

# Prefix this "name" with something unique for your deployment
variable "name" {
default = "covalent-braket"
description = "Name to be used in the new provisioned resources"
}

variable "aws_region" {
default = "us-east-1"
description = "AWS region in which to run Braket"
}

variable "executor_base_image_tag_name" {
default = "latest"
description = "The tag name associate base executor image that is pushed to the provisioned private ecr repo"
}
24 changes: 24 additions & 0 deletions covalent_braket_plugin/assets/infra/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Agnostiq Inc.
#
# This file is part of Covalent.
#
# Licensed under the Apache License 2.0 (the "License"). A copy of the
# License may be obtained with this software package or at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Use of this file is prohibited except in compliance with the License.
# 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.

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.17"
}
}
}

0 comments on commit 9cb1fa4

Please sign in to comment.