Closed3

OpenAI Codex CLIを触ってみる

horie-thorie-t

準備

OpenAIのAPI画面でAPI Keyを発行しておく

インストール

前準備

apt-get等でインストールしているシステムのNodeJSにnpm -g でインストールするとセキュリティ上の問題があるので以下を実行しておく。(Claude Codeでも同じ)

npm list -g --depth=0 > ~/npm-global-packages.txt
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

インストールの実行

npm install -g @openai/codex
horie-thorie-t

起動

適当なgitリポジトリに移動してcodexを起動する

cd repo/<Gitリポジトリ>
codex

以下のような画面になる。

horie-thorie-t

Codexを使ってEKSクラスタを作成してみる

これ以降の引用部分は、Codexへのプロンプトです。

terraformディレクトリにEKSのクラスタを作成するコードを書いてください。EKSはFargetを使って、リージョンはus-west-2 に作成してください。Terraform AWS modulesを使用してください。

指示を出すと以下のようになる。

user
terraformディレクトリにEKSのクラスタを作成するコードを書いてください。EKSはFargetを使って、リージョンはus-west-2
に作成してください。Terraform AWS modulesを使用してください。

    command

    $ ls -R .

    command.stdout (code: 0, duration: 0.1s)

    .:
    README.md


    command

    $ apply_patch << 'EOF'
    *** Begin Patch
    *** Add File: terraform/main.tf
    +terraform {
    +  required_version = ">= 1.0.0"
    +  required_providers {
    +    aws = {
    +      source  = "hashicorp/aws"
    +      version = ">= 4.0"
    +    }
    +  }
    +}
    +
    +provider "aws" {
    +  region = var.region
    +}
    +
    +data "aws_availability_zones" "available" {}
    +
    +module "vpc" {
    +  source  = "terraform-aws-modules/vpc/aws"
    +  version = "3.18.0"
    +  name    = "${var.cluster_name}-vpc"
    +  cidr    = "10.0.0.0/16"
    +  azs     = data.aws_availability_zones.available.names
    +  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
    +  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]
    +  enable_dns_hostnames = true
    +  enable_dns_support   = true
    +}
    +
    +module "eks" {
    +  source                   = "terraform-aws-modules/eks/aws"
    +  version                  = "19.2.0"
    +  cluster_name             = var.cluster_name
    +  cluster_version          = var.cluster_version
    +  vpc_id                   = module.vpc.vpc_id
    +  subnets                  = module.vpc.private_subnets
    +  manage_aws_auth          = true
    +
    +  fargate = {
    +    enabled = true
    +  }
    +
    +  fargate_profiles = [
    +    {
    +      name       = "fp-default"
    +      subnet_ids = module.vpc.private_subnets
    +      selectors = [
    +        {
    +          namespace = "default"
    +        }
    +      ]
    +    }
    +  ]
    +}
    *** End Patch
    EOF

Allow command?

  ❯ Yes (y)
    Explain this command (x)
    Edit or give feedback (e)
    Switch approval mode (s) 
    No, and keep going (n)
    No, and stop for now (esc)

Terrafromのバージョンが古いので e をタイプして以下の指示を出す。

Terraformのバージョンは1.11.3にしてください。

user
Terraformのバージョンは1.11.3にしてください。

    command

    $ apply_patch << 'EOF'
    *** Begin Patch
    *** Add File: terraform/main.tf
    +terraform {
    +  required_version = "= 1.11.3"
    +  required_providers {
    +    aws = {
    +      source  = "hashicorp/aws"
    +      version = ">= 4.0"
    +    }
    +  }
    +}
    +
    +provider "aws" {
    +  region = var.region
    +}
    +
    +data "aws_availability_zones" "available" {}
    +
    +module "vpc" {
    +  source  = "terraform-aws-modules/vpc/aws"
    +  version = "3.18.0"
    +  name    = "${var.cluster_name}-vpc"
    +  cidr    = "10.0.0.0/16"
    +  azs     = data.aws_availability_zones.available.names
    +  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
    +  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]
    +  enable_dns_hostnames = true
    +  enable_dns_support   = true
    +}
    +
    +module "eks" {
    +  source                   = "terraform-aws-modules/eks/aws"
    +  version                  = "19.2.0"
    +  cluster_name             = var.cluster_name
    +  cluster_version          = var.cluster_version
    +  vpc_id                   = module.vpc.vpc_id
    +  subnets                  = module.vpc.private_subnets
    +  manage_aws_auth          = true
    +
    +  fargate = {
    +    enabled = true
    +  }
    +
    +  fargate_profiles = [
    +    {
    +      name       = "fp-default"
    +      subnet_ids = module.vpc.private_subnets
    +      selectors = [
    +        {
    +          namespace = "default"
    +        }
    +      ]
    +    }
    +  ]
    +}
    *** End Patch
    *** Begin Patch
    *** Add File: terraform/variables.tf
    +variable "region" {
    +  description = "AWS region"
    +  type        = string
    +  default     = "us-west-2"
    +}
    +
    +variable "cluster_name" {
    +  description = "EKS cluster name"
    +  type        = string
    +  default     = "example-eks-cluster"
    +}
    +
    +variable "cluster_version" {
    +  description = "Kubernetes version for EKS cluster"
    +  type        = string
    +  default     = "1.24"
    +}
    *** End Patch
    *** Begin Patch
    *** Add File: terraform/outputs.tf
    +output "cluster_name" {
    +  description = "EKS Cluster name"
    +  value       = module.eks.cluster_id
    +}
    +
    +output "cluster_endpoint" {
    +  description = "EKS Cluster endpoint"
    +  value       = module.eks.cluster_endpoint
    +}
    +
    +output "cluster_certificate_authority_data" {
    +  description = "EKS Cluster certificate authority data"
    +  value       = module.eks.cluster_certificate_authority_data
    +}
    *** End Patch
    EOF

指示通りにバージョンが変更された。

このスクラップは4ヶ月前にクローズされました