diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..8f6907c1 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,141 @@ +name: Build and Deploy + +on: + workflow_dispatch: + push: + branches: ["main", "dev"] + +jobs: + build: + environment: main + env: + GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} + runs-on: ubuntu-latest + outputs: + latest_tag: ${{ steps.set_latest_tag.outputs.latest_tag }} + steps: + - name: Checkout Code + uses: actions/checkout@v3 + - name: Install musl cc + uses: awalsh128/cache-apt-pkgs-action@v1 + with: + packages: musl-tools musl-dev musl + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version-file: './go.mod' +# cache: false # Disable Go modules caching + - name: Tag Version + id: tag_version + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.GH_ACCESS_TOKEN }} + release_branches: main + tag_prefix: v + # Removed Go modules cache step + - name: Configure Git for Private Repos + run: | + git config --global url.https://$GH_ACCESS_TOKEN@github.com/opengovern.insteadOf https://github.com/opengovern + - name: Build Render Plugin App + working-directory: ./steampipe-plugin-render + run: make build + - name: Pack Render Plugin Build + working-directory: ./steampipe-plugin-render + run: | + tar -cvf build.tar build + - name: Upload Render Plugin Artifact + uses: actions/upload-artifact@v3 + with: + name: steampipe-plugin-render + path: ./steampipe-plugin-render/build.tar + retention-days: 1 + - name: Build Local Describer App + working-directory: . + run: make local-build + - name: Pack Local Describer Build + working-directory: . + run: | + tar -cvf local.tar local + - name: Upload Local Artifact + uses: actions/upload-artifact@v3 + with: + name: local-og-describer-render + path: ./local.tar + retention-days: 1 + - name: Set Latest Tag Output + id: set_latest_tag + run: | + if [[ -z "${{ steps.tag_version.outputs.new_tag }}" ]]; then + echo "latest_tag=${{ steps.tag_version.outputs.previous_tag }}" >> "$GITHUB_OUTPUT" + else + echo "latest_tag=${{ steps.tag_version.outputs.new_tag }}" >> "$GITHUB_OUTPUT" + fi + + deploy-render-plugin: + needs: build + runs-on: ubuntu-latest + permissions: + id-token: write + contents: read + environment: main + steps: + - name: Checkout Code + uses: actions/checkout@v3 + - name: Download Render Plugin Artifact + uses: actions/download-artifact@v3 + with: + name: steampipe-plugin-render + path: . + - name: Unpack Render Plugin Artifact + run: | + tar -xvf build.tar + - name: Log in to Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GHCR_PAT }} + - name: Build and Push Docker Image for Render Plugin + uses: docker/build-push-action@v4 + with: + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/steampipe-plugin-render:0.0.1 + ghcr.io/${{ github.repository_owner }}/steampipe-plugin-render:${{ needs.build.outputs.latest_tag }} + file: steampipe-plugin-render/docker/Dockerfile + context: . + + deploy-local-describer: + needs: + - build + runs-on: ubuntu-latest + permissions: + id-token: write + contents: read + environment: main + steps: + - name: Checkout Code + uses: actions/checkout@v3 + - name: Download Local Describer Artifact + uses: actions/download-artifact@v3 + with: + name: local-og-describer-render + path: . + - name: Unpack Local Describer Artifact + run: | + tar -xvf local.tar + - name: Log in to Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GHCR_PAT }} + - name: Build and Push Docker Image for Local Describer + uses: docker/build-push-action@v4 + with: + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/og-describer-render:local-latest + ghcr.io/${{ github.repository_owner }}/og-describer-render:local-${{ needs.build.outputs.latest_tag }} + file: DockerFileLocal + context: . diff --git a/.gitignore b/.gitignore index 41b6acde..8b3c8114 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ og-describer-template -.idea \ No newline at end of file +.idea +output.json \ No newline at end of file diff --git a/DockerFileLocal b/DockerFileLocal new file mode 100644 index 00000000..23ed6b11 --- /dev/null +++ b/DockerFileLocal @@ -0,0 +1,8 @@ +FROM docker.io/golang:alpine as build +RUN apk --no-cache add ca-certificates + +FROM scratch +COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY ./local/og-describer-render ./ +ENTRYPOINT [ "./og-describer-render" ] +CMD [ "./og-describer-render" ] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..0fa00c7a --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +.PHONY: build + +local-build: clean + CC=/usr/bin/musl-gcc GOPRIVATE="github.com/opengovern" GOOS=linux GOARCH=amd64 go build -a -v -mod=mod -ldflags "-linkmode external -extldflags '-static' -s -w" -tags musl -o ./local/og-describer-render main.go + +build-cli: clean + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -v -ldflags "-w -extldflags -static" -o ./build/og-render-cli ./command/main.go + +clean: + rm -rf ./local/og-describer-render ./build/og-render-cli diff --git a/steampipe-plugin-render/Makefile b/steampipe-plugin-render/Makefile index 4b483b12..3bd8d35f 100644 --- a/steampipe-plugin-render/Makefile +++ b/steampipe-plugin-render/Makefile @@ -5,4 +5,4 @@ build: GOPRIVATE="github.com/opengovern" CC=/usr/bin/musl-gcc GOOS=linux GOARCH=amd64 go build -v -mod=mod -ldflags "-linkmode external -extldflags '-static' -s -w" -o ./build/steampipe-plugin-render.plugin *.go install: - go build -o $(STEAMPIPE_INSTALL_DIR)/plugins/hub.steampipe.io/plugins/turbot/linode@latest/steampipe-plugin-render.plugin -tags "${BUILD_TAGS}" *.go \ No newline at end of file + go build -o $(STEAMPIPE_INSTALL_DIR)/plugins/hub.steampipe.io/plugins/turbot/render@latest/steampipe-plugin-render.plugin -tags "${BUILD_TAGS}" *.go \ No newline at end of file