From 9e3cd1c57ac25f11a1d4d94789244b1934a2fb56 Mon Sep 17 00:00:00 2001 From: robertlincecum Date: Thu, 15 Feb 2024 14:52:41 -0600 Subject: [PATCH 1/2] go dev --- .github/workflows/build-deploy-go.yml | 351 +++++++++++------- .github/workflows/deploy-dev-common.yml | 21 +- .../workflows/test-remote-dev-workflow-go.yml | 22 ++ go/Makefile | 2 + 4 files changed, 262 insertions(+), 134 deletions(-) create mode 100644 .github/workflows/test-remote-dev-workflow-go.yml create mode 100644 go/Makefile diff --git a/.github/workflows/build-deploy-go.yml b/.github/workflows/build-deploy-go.yml index 1fa4c0d..45735b8 100644 --- a/.github/workflows/build-deploy-go.yml +++ b/.github/workflows/build-deploy-go.yml @@ -1,13 +1,14 @@ -name: Build and Deploy sub-action go +name: Build and Deploy sub-action js on: workflow_call: inputs: env: required: true type: string - awk: - required: true + update_version_command: + required: false type: string + default: npm version patch rails: required: false type: string @@ -24,6 +25,28 @@ on: required: true type: boolean default: false + needs_build: + required: true + type: boolean + build_command: + required: false + type: string + needs_docker: + required: false + type: boolean + default: false + install_command: + required: false + type: string + skip_deploy: + required: false + type: boolean + default: false + include_chart: + required: false + type: boolean + default: false + secrets: GH_PAT: description: 'needed for github login' @@ -34,157 +57,219 @@ on: KUBE_CONFIG: description: 'needed for kube setup' required: true + BUILD_ARGS: + description: 'needed for build args' + required: false + DOCKER_BUILD_ARGS: + description: 'needed for docker build args' + required: false jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - ref: ${{ inputs.branch }} - ssh-key: ${{ secrets.GH_PAT }} + - uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + ssh-key: ${{ secrets.GH_PAT }} - - name: Set Repo Name - run: echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV + - name: Set Repo Name + run: echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV - - name: Install Volta - run: | - curl -sSLf https://get.volta.sh | bash - echo "$HOME/.volta/bin" >> $GITHUB_PATH + - name: Set Repo Name in Camel Case + run: | + repo_name=$(basename ${{ github.repository }}) + camel_case_name=$(echo $repo_name | awk -F- '{for(i=2; i<=NF; i++) $i=toupper(substr($i,1,1)) substr($i,2); }1' OFS="") + echo "CAMEL_CASE_REPO_NAME=$camel_case_name" >> $GITHUB_ENV - - name: Log Node and Npm Versions - run: | - echo node version $(node -v) - echo npm version $(npm -v) + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: 'node' # This will install the latest stable Node.js version + npm-version: 'latest' # This will install the latest npm version - - name: Install yq - run: sudo snap install yq + - name: Log Node and Npm Versions + run: | + echo node version $(node -v) + echo npm version $(npm -v) - - name: get Version - run: echo "VERSION=$(sudo yq eval '.version' package.json -o yaml)" >> $GITHUB_ENV + - name: install semver globally + run: npm install -g semver - - name: Sanity Check Branch - run: ${{ inputs.rails }} + - name: Install yq + run: sudo snap install yq - - name: Sync Chart.yaml version - run: yq eval -i ".appVersion=\"${{ env.VERSION }}\"" ./helm/Chart.yaml + - name: get Version + run: | + VERSION_VALUE=$(sudo cat VERSION) + echo "VERSION=$VERSION_VALUE" + echo "VERSION=$VERSION_VALUE" >> $GITHUB_ENV - - name: Sync values.yaml version - run: yq eval -i ".quaiDashboardApi.image.version=\"${{ env.VERSION }}\"" ./helm/values.yaml + - name: Sanity Check Branch + run: ${{ inputs.rails }} - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: quaibuild - password: ${{ secrets.DOCKER }} + - name: Sync Chart.yaml version + run: yq eval -i ".appVersion=\"${{ env.VERSION }}\"" ./helm/Chart.yaml - - name: Build Docker - run: docker build --build-arg BUILD_ENV=${{ inputs.env }} -t quainetwork/${{ env.REPO_NAME }}:${{ env.VERSION }} . + - name: Sync values.yaml version + run: yq eval -i ".${{ env.CAMEL_CASE_REPO_NAME }}.image.version=\"${{ env.VERSION }}\"" ./helm/values.yaml + - name: Install Dependencies + if: ${{ inputs.install_command }} + run: ${{ inputs.install_command }} - - name: Push to Docker Hub - run: docker push quainetwork/${{ env.REPO_NAME }}:${{ env.VERSION }} + - name: Build + if: ${{ inputs.needs_build }} + run: ${{ inputs.build_command }} - - name: git tag - if: ${{ inputs.update_version }} - run: git tag ${{ env.VERSION }} && HUSKY=0 git push origin tag ${{ env.VERSION }} + - name: Debug secrets + run: | + echo ${{ secrets.DOCKER }} - - uses: stefanzweifel/git-auto-commit-action@v4 - if: ${{ inputs.update_version }} - with: - branch: ${{ inputs.branch }} - env: - HUSKY: 0 + - name: Login to Docker Hub + if: ${{ inputs.needs_docker }} + uses: docker/login-action@v2 + with: + username: quaibuild + password: ${{ secrets.DOCKER }} + + - name: Build Docker + if: ${{ inputs.needs_docker }} + run: | + if [ -n "${{ secrets.DOCKER_BUILD_ARGS }}" ]; then + BUILD_ARGS="" + OLD_IFS=$IFS + IFS=',' + read -ra ARG_ARRAY <<< "${{ secrets.DOCKER_BUILD_ARGS }}" + IFS=$OLD_IFS + for arg in "${ARG_ARRAY[@]}"; do + BUILD_ARGS+=" --build-arg $arg" + done + eval "docker build $BUILD_ARGS -t quainetwork/${{ env.REPO_NAME }}:${{ env.VERSION }} ." + else + docker build -t quainetwork/${{ env.REPO_NAME }}:${{ env.VERSION }} . + fi + + + - name: Push to Docker Hub + if: ${{ inputs.needs_docker }} + run: docker push quainetwork/${{ env.REPO_NAME }}:${{ env.VERSION }} + + - name: git tag + if: ${{ inputs.update_version }} + run: git tag ${{ env.VERSION }} && HUSKY=0 git push origin tag ${{ env.VERSION }} + + - uses: stefanzweifel/git-auto-commit-action@v4 + if: ${{ inputs.update_version }} + with: + branch: ${{ inputs.branch }} + env: + HUSKY: 0 deploy: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - ref: ${{ inputs.branch }} - ssh-key: ${{ secrets.GH_PAT }} - - - name: Install Volta - run: | - curl -sSLf https://get.volta.sh | bash - echo "$HOME/.volta/bin" >> $GITHUB_PATH - - - name: Log Node and Npm Versions - run: | - echo node version $(node -v) - echo npm version $(npm -v) - - - - name: Deploy to cloud - uses: WyriHaximus/github-action-helm3@v2 - if: ${{ inputs.cloud_deploy }} - id: deploy - continue-on-error: true - with: - exec: helm upgrade ${{ env.REPO_NAME }} ./helm --install --namespace=${{ inputs.env }} --values=./helm/env/${{ inputs.env }}.values.yaml - kubeconfig: ${{ secrets.KUBE_CONFIG }} - - - name: Deploy to local from bastion - if: ${{ inputs.cloud_deploy != true }} - continue-on-error: true - run: | - echo installing kubectl... - curl -LO "https://dl.k8s.io/release/v1.25.9/bin/linux/amd64/kubectl" - chmod +x ./kubectl - sudo mv ./kubectl /usr/local/bin/kubectl - echo kubectl installed - echo setting kubeconfig... - echo "${{ secrets.KUBE_CONFIG }}" > kubeconfig.yaml - export KUBECONFIG=kubeconfig.yaml - echo kubeconfig set - echo testing kubectl connection... - kubectl get po - echo clearing bastion helm - kubectl exec -it $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}") -n kube-system -- rm -rf helm - echo bastion helm cleared - echo copying helm to bastion... - kubectl cp -n kube-system ./helm $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}"):/helm - echo helm chart copied to bastion - echo deploying helm chart from bastion... - kubectl exec -it $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}") -n kube-system -- helm upgrade --install ${{ env.REPO_NAME }} ./helm --namespace=${{ inputs.env }} --values=./helm/env/${{ inputs.env }}.values.yaml - echo helm chart deployed!!! - echo cleaning bastion - kubectl exec -it $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}") -n kube-system -- rm -rf helm - echo bastion helm cleared - echo bastion cleaned up - - - name: Install yq - run: sudo snap install yq - - - name: get Version - run: echo "VERSION=$(sudo yq eval '.version' package.json -o yaml)" >> $GITHUB_ENV - - - name: Update version environment variable - if: ${{ inputs.update_version }} - run: echo "VERSION=$(echo $VERSION | ${{ inputs.awk }})" >> $GITHUB_ENV - - - name: Update version - if: ${{ inputs.update_version }} - run: yq eval -i ".version=\"${{ env.VERSION }}\"" package.json -jP - - - name: Update Chart.yaml version - if: ${{ inputs.update_version }} - run: yq eval -P -i ".appVersion=\"${{ env.VERSION }}\"" ./helm/Chart.yaml - - name: Update values.yaml version - run: yq eval -P -i ".quaiDashboardApi.image.version=\"${{ env.VERSION }}\"" ./helm/values.yaml - - - name: Update package-lock.json - continue-on-error: true - run: npm i --package-lock-only --ignore-scripts - - - name: rm kubeconfig - continue-on-error: true - run: rm kubeconfig.yaml - - - uses: stefanzweifel/git-auto-commit-action@v4 - if: ${{ inputs.update_version }} - with: - branch: ${{ inputs.branch }} - env: - HUSKY: 0 + - uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + ssh-key: ${{ secrets.GH_PAT }} + + - name: Set Repo Name + run: echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV + + - name: Set Repo Name in Camel Case + run: | + repo_name=$(basename ${{ github.repository }}) + camel_case_name=$(echo $repo_name | awk -F- '{for(i=2; i<=NF; i++) $i=toupper(substr($i,1,1)) substr($i,2); }1' OFS="") + echo "CAMEL_CASE_REPO_NAME=$camel_case_name" >> $GITHUB_ENV + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: 'node' # This will install the latest stable Node.js version + npm-version: 'latest' # This will install the latest npm version + + - name: Log Node and Npm Versions + run: | + echo node version $(node -v) + echo npm version $(npm -v) + + - name: install semver globally + run: npm install -g semver + + - name: Debug deploy config + run: | + echo cloud_deploy: ${{ inputs.cloud_deploy }} + echo skip_deploy: ${{ inputs.skip_deploy }} + echo env: ${{ inputs.env }} + + - name: Deploy to cloud + uses: WyriHaximus/github-action-helm3@v2 + if: ${{ inputs.cloud_deploy && !inputs.skip_deploy }} + id: deploy + continue-on-error: true + with: + exec: helm upgrade ${{ env.REPO_NAME }} ./helm --install --namespace=${{ inputs.env }} --values=./helm/env/${{ inputs.env }}.values.yaml + kubeconfig: ${{ secrets.KUBE_CONFIG }} + + - name: Deploy to local from bastion + if: ${{ !inputs.cloud_deploy && !inputs.skip_deploy }} + continue-on-error: true + run: | + echo installing kubectl... + curl -LO "https://dl.k8s.io/release/v1.25.9/bin/linux/amd64/kubectl" + chmod +x ./kubectl + sudo mv ./kubectl /usr/local/bin/kubectl + echo kubectl installed + echo setting kubeconfig... + echo "${{ secrets.KUBE_CONFIG }}" > kubeconfig.yaml + export KUBECONFIG=kubeconfig.yaml + echo kubeconfig set + echo testing kubectl connection... + kubectl get po + echo clearing bastion helm + kubectl exec -it $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}") -n kube-system -- rm -rf helm + echo bastion helm cleared + echo copying helm to bastion... + kubectl cp -n kube-system ./helm $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}"):/helm + echo helm chart copied to bastion + echo deploying helm chart from bastion... + kubectl exec -it $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}") -n kube-system -- helm upgrade --install ${{ env.REPO_NAME }} ./helm --namespace=${{ inputs.env }} --values=./helm/env/${{ inputs.env }}.values.yaml + echo helm chart deployed!!! + echo cleaning bastion + kubectl exec -it $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}") -n kube-system -- rm -rf helm + echo bastion helm cleared + echo bastion cleaned up + + - name: Install yq + run: sudo snap install yq + + - name: Update Version + if: ${{ inputs.update_version }} + run: | + ${{ inputs.update_version_command }} + + - name: get Version + run: | + VERSION_VALUE=$(sudo cat VERSION) + echo "VERSION=$VERSION_VALUE" + echo "VERSION=$VERSION_VALUE" >> $GITHUB_ENV + + - name: Update Chart.yaml version + if: ${{ inputs.update_version && inputs.include_chart }} + run: yq eval -P -i ".appVersion=\"${{ env.VERSION }}\"" ./helm/Chart.yaml + - name: Update values.yaml version + run: yq eval -P -i ".${{ env.CAMEL_CASE_REPO_NAME }}.image.version=\"${{ env.VERSION }}\"" ./helm/values.yaml + + - name: rm kubeconfig + if: ${{ !inputs.skip_deploy }} + continue-on-error: true + run: rm kubeconfig.yaml + + - uses: stefanzweifel/git-auto-commit-action@v4 + if: ${{ inputs.update_version }} + with: + branch: ${{ inputs.branch }} + env: + HUSKY: 0 diff --git a/.github/workflows/deploy-dev-common.yml b/.github/workflows/deploy-dev-common.yml index 149dc7a..fa04f1c 100644 --- a/.github/workflows/deploy-dev-common.yml +++ b/.github/workflows/deploy-dev-common.yml @@ -7,6 +7,10 @@ on: required: true type: boolean default: false + build_command: + description: 'Command to run to build' + type: string + required: false install_command: description: 'Command to run to install dependencies' type: string @@ -19,6 +23,14 @@ on: required: false type: boolean default: false + include_chart: + required: false + type: boolean + default: false + needs_docker: + required: false + type: boolean + default: false env: required: false type: string @@ -121,11 +133,18 @@ jobs: DOCKER: ${{ secrets.DOCKER }} GH_PAT: ${{ secrets.GH_PAT }} KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} + DOCKER_BUILD_ARGS: ${{ secrets.DOCKER_BUILD_ARGS }} with: env: ${{ inputs.env }} - awk: awk -F. '{print $1"."$2"."$3"."$4+1}' + update_version_command: "echo \"v$(semver -i prerelease $(sed 's/^v//' VERSION) --preid=pre)\" > VERSION" update_version: true cloud_deploy: false + needs_build: ${{ inputs.needs_build }} + install_command: ${{ inputs.install_command }} + skip_deploy: ${{ inputs.skip_deploy }} + build_command: ${{ inputs.build_command }} + needs_docker: ${{ inputs.needs_docker }} + include_chart: ${{ inputs.include_chart }} buildDeployDevElixir: needs: detect-language diff --git a/.github/workflows/test-remote-dev-workflow-go.yml b/.github/workflows/test-remote-dev-workflow-go.yml new file mode 100644 index 0000000..5e4272f --- /dev/null +++ b/.github/workflows/test-remote-dev-workflow-go.yml @@ -0,0 +1,22 @@ +name: Test Use of Common Dev Workflow +on: + pull_request: + types: [closed] + branches: [ "main" ] +jobs: + call-common-workflow: + uses: dominant-strategies/quai-cicd/.github/workflows/deploy-dev-common.yml@main + with: + needs_build: true + build_command: "make go-quai" + needs_docker: false + include_chart: false + needs_docs: false + cloud_deploy: false + skip_deploy: true + + secrets: + DOCKER: ${{ secrets.DOCKER }} + GH_PAT: ${{ secrets.GH_PAT }} + KUBE_CONFIG: ${{ secrets.KUBECONFIG_LOCAL }} + DOCKER_BUILD_ARGS: 'BUILD_ENV=quai-dev,LOCAL_GCP_CAPTCHA=${{ secrets.LOCAL_GCP_CAPTCHA }}' diff --git a/go/Makefile b/go/Makefile new file mode 100644 index 0000000..da71bb8 --- /dev/null +++ b/go/Makefile @@ -0,0 +1,2 @@ +go-quai: + echo "making go-quai" \ No newline at end of file From 0c760ff1d966da241e5ae043fe2b65fe0f163ab6 Mon Sep 17 00:00:00 2001 From: robertlincecum Date: Thu, 15 Feb 2024 15:22:32 -0600 Subject: [PATCH 2/2] test go dev common --- .../workflows/test-remote-dev-workflow-go.yml | 22 ------------------- .../workflows/test-remote-dev-workflow.yml | 7 ++++-- .last_dir | 2 +- Dockerfile | 7 +++--- Makefile | 3 +++ VERSION | 1 + go.mod | 4 ++++ go/Makefile | 3 ++- go/VERSION | 1 + main.go | 8 +++++++ package.json | 12 ---------- sample.ts | 2 -- tsconfig.json | 8 ------- 13 files changed, 29 insertions(+), 51 deletions(-) delete mode 100644 .github/workflows/test-remote-dev-workflow-go.yml create mode 100644 Makefile create mode 100644 VERSION create mode 100644 go.mod create mode 100644 go/VERSION create mode 100644 main.go delete mode 100644 package.json delete mode 100644 sample.ts delete mode 100644 tsconfig.json diff --git a/.github/workflows/test-remote-dev-workflow-go.yml b/.github/workflows/test-remote-dev-workflow-go.yml deleted file mode 100644 index 5e4272f..0000000 --- a/.github/workflows/test-remote-dev-workflow-go.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Test Use of Common Dev Workflow -on: - pull_request: - types: [closed] - branches: [ "main" ] -jobs: - call-common-workflow: - uses: dominant-strategies/quai-cicd/.github/workflows/deploy-dev-common.yml@main - with: - needs_build: true - build_command: "make go-quai" - needs_docker: false - include_chart: false - needs_docs: false - cloud_deploy: false - skip_deploy: true - - secrets: - DOCKER: ${{ secrets.DOCKER }} - GH_PAT: ${{ secrets.GH_PAT }} - KUBE_CONFIG: ${{ secrets.KUBECONFIG_LOCAL }} - DOCKER_BUILD_ARGS: 'BUILD_ENV=quai-dev,LOCAL_GCP_CAPTCHA=${{ secrets.LOCAL_GCP_CAPTCHA }}' diff --git a/.github/workflows/test-remote-dev-workflow.yml b/.github/workflows/test-remote-dev-workflow.yml index 0edca8a..5e4272f 100644 --- a/.github/workflows/test-remote-dev-workflow.yml +++ b/.github/workflows/test-remote-dev-workflow.yml @@ -8,12 +8,15 @@ jobs: uses: dominant-strategies/quai-cicd/.github/workflows/deploy-dev-common.yml@main with: needs_build: true - install_command: "npm ci" + build_command: "make go-quai" + needs_docker: false + include_chart: false + needs_docs: false cloud_deploy: false skip_deploy: true + secrets: DOCKER: ${{ secrets.DOCKER }} GH_PAT: ${{ secrets.GH_PAT }} KUBE_CONFIG: ${{ secrets.KUBECONFIG_LOCAL }} - BUILD_ARGS: 'BUILD_ENV=production' DOCKER_BUILD_ARGS: 'BUILD_ENV=quai-dev,LOCAL_GCP_CAPTCHA=${{ secrets.LOCAL_GCP_CAPTCHA }}' diff --git a/.last_dir b/.last_dir index e082170..4023f20 100644 --- a/.last_dir +++ b/.last_dir @@ -1 +1 @@ -ts +go diff --git a/Dockerfile b/Dockerfile index a9e4746..c41ff3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,10 @@ -FROM node:14 +FROM golang:1.17 WORKDIR /app COPY ./ . -RUN npm install -CMD ["npm", "start"] +RUN go build -o main . + +CMD ["./main"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d1c64a9 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +## simple makefile with make go-quai that just logs the command +go-quai: + @echo "go-quai" diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..3e3abdb --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +v1.0.0-pre.1 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d2dcad4 --- /dev/null +++ b/go.mod @@ -0,0 +1,4 @@ +module sample-go-project + +go 1.17 + diff --git a/go/Makefile b/go/Makefile index da71bb8..d1c64a9 100644 --- a/go/Makefile +++ b/go/Makefile @@ -1,2 +1,3 @@ +## simple makefile with make go-quai that just logs the command go-quai: - echo "making go-quai" \ No newline at end of file + @echo "go-quai" diff --git a/go/VERSION b/go/VERSION new file mode 100644 index 0000000..3e3abdb --- /dev/null +++ b/go/VERSION @@ -0,0 +1 @@ +v1.0.0-pre.1 diff --git a/main.go b/main.go new file mode 100644 index 0000000..5b2b093 --- /dev/null +++ b/main.go @@ -0,0 +1,8 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello from Go!") +} + diff --git a/package.json b/package.json deleted file mode 100644 index 638379b..0000000 --- a/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "sample-ts-project", - "version": "1.0.0", - "scripts": { - "build": "tsc" - }, - "dependencies": {}, - "devDependencies": { - "typescript": "^4.5.2" - } -} - diff --git a/sample.ts b/sample.ts deleted file mode 100644 index ccc4592..0000000 --- a/sample.ts +++ /dev/null @@ -1,2 +0,0 @@ -console.log("Hello from TypeScript"); - diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index bcc1941..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "module": "commonjs" - }, - "include": ["*.ts"] -} -