From 5b0f52b08e92df6c049be7a38e59157345b3bf54 Mon Sep 17 00:00:00 2001 From: Aviram Hassan Date: Sun, 3 Nov 2024 15:47:04 +0200 Subject: [PATCH 1/2] wip have overlays --- .../build-ip-visit-sqs-consumer.yaml | 35 ++++++++++++++++++ .gitignore | 3 +- README.md | 7 ++++ ip-info/app.yaml => base/ip-info.yaml | 0 .../app.yaml => base/ip-visit-consumer.yaml | 0 .../app.yaml => base/ip-visit-counter.yaml | 4 +- kafka.yaml => base/kafka.yaml | 0 base/kustomization.yaml | 8 ++++ redis.yaml => base/redis.yaml | 0 ip-visit-counter/main.go | 12 ++++-- kustomization.yaml | 14 ------- overlays/.DS_Store | Bin 0 -> 10244 bytes .../gke/certificate.yaml | 0 ingress.yaml => overlays/gke/ingress.yaml | 0 .../gke/ip-visit-frontend.yaml | 0 .../gke/ip-visit-sqs-consumer.yaml | 0 overlays/gke/kustomization.yaml | 10 +++++ secret.yaml => overlays/gke/secret.yaml | 0 .../gke/sqs-queueregistry.yaml | 0 overlays/local/kustomization.yaml | 6 +++ overlays/local/patch-nodeport.yaml | 6 +++ 21 files changed, 85 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/build-ip-visit-sqs-consumer.yaml rename ip-info/app.yaml => base/ip-info.yaml (100%) rename ip-visit-consumer/app.yaml => base/ip-visit-consumer.yaml (100%) rename ip-visit-counter/app.yaml => base/ip-visit-counter.yaml (94%) rename kafka.yaml => base/kafka.yaml (100%) create mode 100644 base/kustomization.yaml rename redis.yaml => base/redis.yaml (100%) delete mode 100644 kustomization.yaml create mode 100644 overlays/.DS_Store rename certificate.yaml => overlays/gke/certificate.yaml (100%) rename ingress.yaml => overlays/gke/ingress.yaml (100%) rename ip-visit-frontend/app.yaml => overlays/gke/ip-visit-frontend.yaml (100%) rename ip-visit-sqs-consumer/app.yaml => overlays/gke/ip-visit-sqs-consumer.yaml (100%) create mode 100644 overlays/gke/kustomization.yaml rename secret.yaml => overlays/gke/secret.yaml (100%) rename ip-visit-sqs-consumer/queueregistry.yaml => overlays/gke/sqs-queueregistry.yaml (100%) create mode 100644 overlays/local/kustomization.yaml create mode 100644 overlays/local/patch-nodeport.yaml 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/overlays/.DS_Store b/overlays/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..638c236a27aaf8f16a4e806178d7a0eeaa882507 GIT binary patch literal 10244 zcmeGhZEO@(@XfZsu3hLWP+;+}Csk6B%JqY9(CY`ar6nb_wAT-;cehKsc5k=d?p+a5 zQ{z`O@W-#{FEqvk6GaonA0~n^O3)s?B%iVXA)q{Q#}by4K_cCr{ zJUzg$ZpX0_xp_R%V;bW_ba9hodvVh?(pJno@(+fFGm0L>G`D#yZPfYEPnMud)G7lI-wA4j)+YsHA zHnON@Z_=?cDcc>QWy!de%vf>HXs|5CjI>fWnRYB|m*bkA>DYZS&)DzfHY!+(^}9~m zYvP*?QJQg$-3IPuW{qat5w}{%p4K_WwsCumw2QDZ8WCzM#}+IN-G1llwe_3sZEEe< zb*_|_EnK9QtNmzO+cWo>M!GNVCJkFR?cqJ+rtXdOW=+>jSVp%UPZ>%X)GJ(SnYLVu zWfJDY8Pj`2rj;_MuFxvfK^+gW)6v;(x=fD?{*_vVHo#Vz(gu#YECg0*Rcg13Mv!S- zFy5_JtKFmc@)ha|N<^*I_E_V(ZimT5ncpr_gpm+^lZZV)zDAsEUgxT_ec% zX${%~?8zN**XtZJY<8-XVy#(g(fZwyc-rV3NB@)QX+dv8I)8__!o;@grst&b%nQqC zDQeOw%YAIi23_@5HpTCVD*@UO2x}nRB|z=xQ%$lYPV?kC8*<2zj4;L{5+|$$4^_{7il&SIAZJCrD5PDwM+#SOyxbgtZWXTBw7q z&ZNT`i_|W4h|^2C5F04eO4^I~ zR3Q0Re$vq!1X62T>khSJ)(6se3wY=(E?=@V%;IU|w#I9&Cww*Mp7~DCUwc7(a8Ku< zHO)oOVSwElQg5rs#ozR}+=C%v?3bCJ(|JC3Rxj-(FAIWdz z3e1HPpilu-=*^oU3N3Iy`g1$%gdXTckM8IGybp%KM4$E`16kM)2jFpd0-l7Y;Ti7N zFL1wp6<&ka;SD$j@4&n89vp`ga1uU-PvBGZ^snGs_#Q4!^WL3>-V47>d2h;TZuT#% z<(e}uSDzU@)sVlcUt85)87wbc9UI9{ElEjJi->1?I>oJwqZ`#O`DNn2Q zb?g5|D$UcWFrAWb&{FxUK}ro$YLHU@K}szQrXZ~bX?6M!#@U`$^E@~|wQf25RN@Pf zS_?R)((Cm(3R7$t^G(ohss)O~Zedm#Z@=;X|2OrS!DfL40t?J83qWymS92qtDOd4N zKOVbl4`Y82J8O(@Qa~<(1HX<($gkrOVb}3h*cq>XS;gm3pEfBV7e^j0j__alGhpUL WT2TK7^?zZ7pK_*tp!^T(|Gxljz>+oq literal 0 HcmV?d00001 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 From 9053b4fbdeb0abd497035d82522b3ccc86e80640 Mon Sep 17 00:00:00 2001 From: Aviram Hassan Date: Sun, 3 Nov 2024 16:37:25 +0200 Subject: [PATCH 2/2] .. --- overlays/.DS_Store | Bin 10244 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 overlays/.DS_Store diff --git a/overlays/.DS_Store b/overlays/.DS_Store deleted file mode 100644 index 638c236a27aaf8f16a4e806178d7a0eeaa882507..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10244 zcmeGhZEO@(@XfZsu3hLWP+;+}Csk6B%JqY9(CY`ar6nb_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