Skip to content

Commit

Permalink
Merge pull request #1 from 4cm3/dev
Browse files Browse the repository at this point in the history
First test
  • Loading branch information
4cm3 authored Dec 18, 2024
2 parents 40fe412 + 6f84aac commit 606d926
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 2 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build-and-push-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: build-and-push-container

on:
workflow_dispatch:
inputs:
environment:
description: env to be used
required: true
type: choice
options:
- dev
default: dev

jobs:
build-and-push:
name: build-and-push-container
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: config-aws-credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: login-to-ecr
id: login-to-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: and push docker image to ECR
env:
REGISTRY: ${{ steps.login-to-ecr.outputs.registry }}
REPOSITORY: ipfs-metadata-${{ inputs.environment }}
TAG: ipfs-metadata-${{ github.run_number }}
run: |
docker build -t $REGISTRY/$REPOSITORY:$TAG .
docker push $REGISTRY/$REPOSITORY:$TAG
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
.env
.env
ipfs_fetcher
# Terraform
.terraform/
.terraform.*
terraform.tfstate
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.23-alpine AS build

WORKDIR /app

COPY go.mod ./
COPY *.go ./

RUN go mod tidy
RUN go build -o /ipfs_fetcher

## Using a smaller image to run our application
FROM scratch
WORKDIR /
COPY --from=build /ipfs_fetcher /ipfs_fetcher
EXPOSE 8080
ENTRYPOINT ["/ipfs_fetcher"]
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docker-build:
docker build -t ipfs-metadata .

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ This application scrapes NFT metadata from IPFS using a CSV list of IPFS CIDs an

```
git clone https://github.com/shawnwollenberg/ipfs-metadata.git
cd nft_scraper
```

### Step 2: Set Up PostgreSQL
Expand Down
17 changes: 17 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ipfs-metadata

## Build and run application
## CI/CD pipeline

### Requirements

* Create following AWS variables as secrets in the github repository.

```
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
```

## Deploy infrastructure with terraform
## Deploy application
9 changes: 9 additions & 0 deletions infrastructure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Infrastructure repo

Simple repo to keep track of infra changes for the project

## Prerequisites

* An IAM user with admin permissions + aws cli access
* Create a bucket for each env (check infrastructure/dev/ecr/providers.tf to find/change the file name)
* Create the DynamoDB table
33 changes: 33 additions & 0 deletions infrastructure/dev/ecr/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
locals {
service = "ipfs-metadata"
environment = "dev"
}

module "ecr" {
source = "terraform-aws-modules/ecr/aws"

repository_name = "${local.service}-${local.environment}"

repository_lifecycle_policy = jsonencode({
rules = [
{
rulePriority = 1,
description = "Keep last 5 images",
selection = {
tagStatus = "tagged",
tagPrefixList = ["v"],
countType = "imageCountMoreThan",
countNumber = 5
},
action = {
type = "expire"
}
}
]
})

tags = {
Terraform = "true"
Environment = local.environment
}
}
27 changes: 27 additions & 0 deletions infrastructure/dev/ecr/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}

backend "s3" {
region = "us-west-2"
bucket = "ipfs-tfstate-bon4ca"
key = "dev/ecr/terraform.tfstate"
dynamodb_table = "ipfs-tf-tfstate"
encrypt = true
}
}

provider "aws" {
region = "us-west-2"

default_tags {
tags = {
Application = "ipfs-metadata"
Environment = "dev"
}
}
}

0 comments on commit 606d926

Please sign in to comment.