From cae66973a0a51fdf63d90d3aa108e297d6195a0b Mon Sep 17 00:00:00 2001 From: PranoSA Date: Wed, 21 Feb 2024 16:53:59 -0800 Subject: [PATCH] Added Github CI --- .github/workflows/push_docker.yml | 61 +++++++++++++++++++++++++ .terraformrc | 11 +++++ Dockerfile | 65 +++++++++++++++++++++++++++ examples/america-themed_app/main.tf | 8 ++-- examples/amphibian_themed_app/main.tf | 6 +-- 5 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/push_docker.yml create mode 100644 .terraformrc create mode 100644 Dockerfile diff --git a/.github/workflows/push_docker.yml b/.github/workflows/push_docker.yml new file mode 100644 index 0000000..20fea90 --- /dev/null +++ b/.github/workflows/push_docker.yml @@ -0,0 +1,61 @@ +name: unicode-docker-repository +run-name: unicode-docker-run +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Docker buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push default image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: pcadler/unicode-terraform-plugin:latest + target: default + + - name: Build and push american image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ghcr.io/${{ github.repository }}/american-latest + target: american + + - name: Build and push amphibian image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: pcadler/unicode-terraform-plugin:amphibian-latest + target: amphibian + + - name: Build and push halloween image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: pcadler/unicode-terraform-plugin:halloween-latest + target: halloween + + #test_docker_build: + + #test_apply_and_destroy: + + #push_docker_images: diff --git a/.terraformrc b/.terraformrc new file mode 100644 index 0000000..2cf122d --- /dev/null +++ b/.terraformrc @@ -0,0 +1,11 @@ +provider_installation { + + dev_overrides { + "hashicorp.com/edu/unicode" = "/home/app" + } + + # For all other providers, install them directly from their origin provider + # registries as normal. If you omit this, Terraform will _only_ use + # the dev_overrides block, and so no other providers will be available. + direct {} +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..aa6e2e5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,65 @@ +# Build Out Provider +FROM golang:1.21-alpine AS compiler +WORKDIR /terraform-provider-unicode +COPY . . +#RUN rm $GOPATH/go.mod +RUN go build . +RUN chmod +x terraform-provider-unicode +RUN chown 1000:1000 terraform-provider-unicode +RUN chgrp 1000 terraform-provider-unicode + +# Temporary Container TO Build User +FROM debian:stretch-slim as auth +RUN groupadd -g 1000 app && useradd -u 1000 -g 1000 -m app + +# Copy Into Terraform Container +FROM hashicorp/terraform:light as default +# Make User 1000 +COPY --from=auth /etc/passwd /etc/passwd +COPY --from=auth /etc/group /etc/group +COPY --from=auth /home/app /home/app +RUN chown 1000:1000 /home/app +# Make Home Directory +COPY --from=compiler /terraform-provider-unicode/terraform-provider-unicode /home/app/terraform-provider-unicode +COPY --from=compiler /terraform-provider-unicode/.terraformrc /home/app/.terraformrc +RUN chown 1000:1000 /home/app/.terraformrc +RUN chown 1000:1000 /home/app/terraform-provider-unicode +RUN chmod +x /home/app/terraform-provider-unicode +# Now Switch to User app +USER app +WORKDIR /home/app +ENTRYPOINT ["terraform", "apply", "-auto-approve"] +CMD ["--var", "user=default"] +# does this user follow you arround? + +# American App -> Take in variables and output +FROM default as american +USER app +WORKDIR /home/app +RUN mkdir america-themed-app +COPY --from=compiler /terraform-provider-unicode/examples/america-themed_app/ /home/app/america-themed-app +WORKDIR /home/app/america-themed-app +#&& terraform init +ENTRYPOINT [ "terraform", "apply","-auto-approve"] +CMD ["--var", "user=default" ] + +FROM default as amphibian +USER app +WORKDIR /home/app +RUN mkdir amphibian-themed-app +COPY --from=compiler /terraform-provider-unicode/examples/amphibian_themed_app/ /home/app/amphibian-themed-app +WORKDIR /home/app/amphibian-themed-app +#&& terraform init +ENTRYPOINT [ "terraform","apply","-auto-approve"] +CMD ["--var", "user=default" ] + + +FROM default as halloween +USER app +WORKDIR /home/app +RUN mkdir halloween-themed-app +COPY --from=compiler /terraform-provider-unicode/examples/halloween_themed_app/ /home/app/halloween-themed-app +WORKDIR /home/app/halloween-themed-app + +ENTRYPOINT [ "terraform", "apply","-auto-approve"] +CMD ["--var", "user=default" ] diff --git a/examples/america-themed_app/main.tf b/examples/america-themed_app/main.tf index f0acf37..d4c8768 100644 --- a/examples/america-themed_app/main.tf +++ b/examples/america-themed_app/main.tf @@ -25,21 +25,21 @@ resource "unicode_app" "america_application_v2" { } resource "unicode_unicode_string" "america_string" { - app_id = unicode_app.ammerica_application_v2.id + app_id = unicode_app.america_application_v2.id value = "πŸ‡ΊπŸ‡Έ" } resource "unicode_unicode_string" "football_string" { - app_id = unicode_app.ammerica_application_v2.id + app_id = unicode_app.america_application_v2.id value = "🏈" } resource "unicode_unicode_string" "baseball_string" { - app_id = unicode_app.ammerica_application_v2.id + app_id = unicode_app.america_application_v2.id value = "⚾" } resource "unicode_unicode_string" "fastfood_string" { - app_id = unicode_app.ammerica_application_v2.id + app_id = unicode_app.america_application_v2.id value = "πŸ”πŸ₯€πŸŸπŸŒ­" } diff --git a/examples/amphibian_themed_app/main.tf b/examples/amphibian_themed_app/main.tf index d84bf04..13b6e62 100644 --- a/examples/amphibian_themed_app/main.tf +++ b/examples/amphibian_themed_app/main.tf @@ -16,9 +16,9 @@ provider "unicode" { resource "unicode_app" "amphibian_application" { name = "Amphibian Application" description = "Amphibian App v2" - id = "1215902212-123091SDSA" - updated_at = "2024-02-07T00:00:00Z" - created_at = "2024-02-07T10:00:00Z" + //id = "1215902212-123091SDSA" + updated_at = "2024-02-07T00:00:00Z" + created_at = "2024-02-07T10:00:00Z" } resource "unicode_unicode_string" "frog_string" {