diff --git a/.github/workflows/build-ip-visit-sqs-consumer.yaml b/.github/workflows/build-ip-visit-sqs-consumer.yaml new file mode 100644 index 0000000..270e759 --- /dev/null +++ b/.github/workflows/build-ip-visit-sqs-consumer.yaml @@ -0,0 +1,35 @@ +name: Release ip visit sqs consumer +on: + push: + branches: [main] + workflow_dispatch: + +jobs: + image: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v3 + with: + file: ip-visit-sqs-consumer/Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7 + context: ip-visit-sqs-consumer/ + push: true + tags: | + ghcr.io/metalbear-co/playground-ip-visit-sqs-consumer:latest \ No newline at end of file diff --git a/.gitignore b/.gitignore index 76773d8..777f742 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -ip-visit-sqs-consumer/ip-visit-sqs-consumer \ No newline at end of file +ip-visit-sqs-consumer/ip-visit-sqs-consumer +**/.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 8371472..4cde5c6 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,10 @@ To enable SQS: 6. `aws iam create-policy --policy-name SQSPlaygroundPolicy --policy-document file://ip-visit-sqs-consumer/policy.json` 7. `aws iam attach-user-policy --policy-arn arn:aws:iam::526936346962:policy/SQSPlaygroundPolicy --user-name SQSPlayground` 8. Set Region in app.yaml in `ip-visit-counter` and `ip-visit-sqs-consumer` + + +## Minikube/Local + +``` +kubectl apply -k ./base/local +``` \ No newline at end of file diff --git a/ip-info/app.yaml b/base/ip-info.yaml similarity index 100% rename from ip-info/app.yaml rename to base/ip-info.yaml diff --git a/ip-visit-consumer/app.yaml b/base/ip-visit-consumer.yaml similarity index 100% rename from ip-visit-consumer/app.yaml rename to base/ip-visit-consumer.yaml diff --git a/ip-visit-counter/app.yaml b/base/ip-visit-counter.yaml similarity index 94% rename from ip-visit-counter/app.yaml rename to base/ip-visit-counter.yaml index 307f8d6..732695b 100644 --- a/ip-visit-counter/app.yaml +++ b/base/ip-visit-counter.yaml @@ -71,8 +71,10 @@ spec: secretKeyRef: name: aws-credentials key: AWS_ACCESS_KEY_ID + optional: true - name: AWS_SECRET_ACCESS_KEY valueFrom: secretKeyRef: name: aws-credentials - key: AWS_SECRET_ACCESS_KEY \ No newline at end of file + key: AWS_SECRET_ACCESS_KEY + optional: true \ No newline at end of file diff --git a/kafka.yaml b/base/kafka.yaml similarity index 100% rename from kafka.yaml rename to base/kafka.yaml diff --git a/base/kustomization.yaml b/base/kustomization.yaml new file mode 100644 index 0000000..16c63d4 --- /dev/null +++ b/base/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- kafka.yaml +- redis.yaml +- ip-visit-counter.yaml +- ip-visit-consumer.yaml +- ip-info.yaml diff --git a/redis.yaml b/base/redis.yaml similarity index 100% rename from redis.yaml rename to base/redis.yaml diff --git a/ip-visit-counter/main.go b/ip-visit-counter/main.go index 3b77424..7a350d4 100644 --- a/ip-visit-counter/main.go +++ b/ip-visit-counter/main.go @@ -167,7 +167,9 @@ func getCount(c *gin.Context) { RedisClient.Expire(c, key, RedisKeyTtl) message, _ := json.Marshal(IpMessage{Ip: ip}) - SendSqsMessage(c, message) + if sqsClient != nil { + SendSqsMessage(c, message) + } err = KafkaWriter.WriteMessages(c, kafka.Message{Value: []byte(message)}) if err != nil { @@ -227,10 +229,12 @@ func main() { } SetupKafka(config.KafkaAddress, config.KafkaTopic) - err = SetupSqs(config.SqsQueueName) + if config.SqsQueueName != "" { + err = SetupSqs(config.SqsQueueName) - if err != nil { - panic(err) + if err != nil { + panic(err) + } } router := gin.Default() diff --git a/kustomization.yaml b/kustomization.yaml deleted file mode 100644 index 87233a5..0000000 --- a/kustomization.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -resources: - - ingress.yaml - - certificate.yaml - - kafka.yaml - - redis.yaml - - secret.yaml - - ip-visit-counter/app.yaml - - ip-visit-consumer/app.yaml - - ip-info/app.yaml - - ip-visit-frontend/app.yaml - - ip-visit-sqs-consumer/app.yaml - - ip-visit-sqs-consumer/queueregistry.yaml \ No newline at end of file diff --git a/certificate.yaml b/overlays/gke/certificate.yaml similarity index 100% rename from certificate.yaml rename to overlays/gke/certificate.yaml diff --git a/ingress.yaml b/overlays/gke/ingress.yaml similarity index 100% rename from ingress.yaml rename to overlays/gke/ingress.yaml diff --git a/ip-visit-frontend/app.yaml b/overlays/gke/ip-visit-frontend.yaml similarity index 100% rename from ip-visit-frontend/app.yaml rename to overlays/gke/ip-visit-frontend.yaml diff --git a/ip-visit-sqs-consumer/app.yaml b/overlays/gke/ip-visit-sqs-consumer.yaml similarity index 100% rename from ip-visit-sqs-consumer/app.yaml rename to overlays/gke/ip-visit-sqs-consumer.yaml diff --git a/overlays/gke/kustomization.yaml b/overlays/gke/kustomization.yaml new file mode 100644 index 0000000..1c7046d --- /dev/null +++ b/overlays/gke/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../base + - ingress.yaml + - certificate.yaml + - secret.yaml + - ip-visit-frontend.yaml + - ip-visit-sqs-consumer.yaml + - sqs-queueregistry.yaml \ No newline at end of file diff --git a/secret.yaml b/overlays/gke/secret.yaml similarity index 100% rename from secret.yaml rename to overlays/gke/secret.yaml diff --git a/ip-visit-sqs-consumer/queueregistry.yaml b/overlays/gke/sqs-queueregistry.yaml similarity index 100% rename from ip-visit-sqs-consumer/queueregistry.yaml rename to overlays/gke/sqs-queueregistry.yaml diff --git a/overlays/local/kustomization.yaml b/overlays/local/kustomization.yaml new file mode 100644 index 0000000..215c0df --- /dev/null +++ b/overlays/local/kustomization.yaml @@ -0,0 +1,6 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../../base +patches: +- path: patch-nodeport.yaml diff --git a/overlays/local/patch-nodeport.yaml b/overlays/local/patch-nodeport.yaml new file mode 100644 index 0000000..9918fee --- /dev/null +++ b/overlays/local/patch-nodeport.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Service +metadata: + name: ip-visit-counter +spec: + type: NodePort \ No newline at end of file