From 01c3ff00fa5d95a0cd55bbe96326f25b022a8e1e Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Wed, 18 Oct 2023 05:34:48 -0700 Subject: [PATCH] Use Dockerfile Signed-off-by: Tamal Saha --- .github/workflows/ci.yml | 6 +- .github/workflows/deploy.yml | 88 ++++++++++++++++++++++++ .github/workflows/preview-website.yml | 4 +- .github/workflows/release-tracker.yml | 3 +- .github/workflows/release.yml | 98 +++++++++++++++++++-------- .github/workflows/release_old.yml | 75 ++++++++++++++++++++ Dockerfile | 16 +++++ Makefile | 46 +++++++++++++ 8 files changed, 300 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/release_old.yml create mode 100644 Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e32277323..31e4dcb4f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,10 +18,10 @@ jobs: name: Build runs-on: ubuntu-20.04 steps: - - name: Use Node.js 14.x + - name: Use Node.js 18.x uses: actions/setup-node@v1 with: - node-version: '16' + node-version: '18' check-latest: true - uses: actions/checkout@v1 @@ -49,8 +49,6 @@ jobs: npm install - name: Build - env: - GOOGLE_CUSTOM_SEARCH_API_KEY: ${{ secrets.GOOGLE_CUSTOM_SEARCH_API_KEY }} run: make gen-prod # - name: Check links diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000000..1cc8bcc7ec --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,88 @@ +name: Deploy + +on: + workflow_dispatch: + inputs: + cluster: + description: 'Cluster' + required: true + type: choice + options: + - ninja + - prod + version: + description: 'Tag' + # required: true + type: string + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build + runs-on: f0 + steps: + - uses: actions/checkout@v1 + + - uses: actions/setup-node@v2 + with: + node-version: '18' + check-latest: true + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install Linode CLI + run: | + python -m pip install --upgrade pip + pip --version + pip install setuptools + pip install linode-cli --upgrade + + - name: Install kubectl + run: | + curl -LO https://dl.k8s.io/release/v1.25.2/bin/linux/amd64/kubectl + chmod +x ./kubectl + sudo mv ./kubectl /usr/local/bin/kubectl + + - name: Install yq + run: | + curl -fsSL -o yqq https://github.com/mikefarah/yq/releases/download/3.3.0/yq_linux_amd64 + chmod +x yqq + sudo mv yqq /usr/local/bin/yqq + pip3 install yq + + - name: Install Hugo + run: | + curl -fsSL -o hugo_extended.deb https://github.com/gohugoio/hugo/releases/download/v0.111.1/hugo_extended_0.111.1_linux-amd64.deb + sudo dpkg -i hugo_extended.deb + + - name: Install Hugo Tools + run: | + curl -fsSL -o hugo-tools https://github.com/appscodelabs/hugo-tools/releases/download/v0.2.23/hugo-tools-linux-amd64 + chmod +x hugo-tools + sudo mv hugo-tools /usr/local/bin/hugo-tools + + # - name: Setup upterm session + # uses: lhotari/action-upterm@v1 + + - name: Deploy + env: + REGISTRY: ghcr.io/appscode + LINODE_CLI_TOKEN: ${{ secrets.LINODE_CLI_TOKEN }} + CLUSTER: ${{ inputs.cluster }} + run: | + lke_id=19953 # ninja cluster + if [ "$CLUSTER" = "prod" ]; then + lke_id=25516 # prod cluster + fi + echo "connect to LKE cluster $lke_id" + mkdir -p ~/.kube + linode-cli lke kubeconfig-view $lke_id --json | jq -r .[0].kubeconfig | base64 -d > ~/.kube/config + kubectl get nodes + echo "deploy docker image" + make deploy-to-linode TAG=${{ inputs.version }} diff --git a/.github/workflows/preview-website.yml b/.github/workflows/preview-website.yml index e79d1c8b95..6a3a932132 100644 --- a/.github/workflows/preview-website.yml +++ b/.github/workflows/preview-website.yml @@ -20,13 +20,13 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - go-version: ^1.20 + go-version: ^1.21 id: go - name: Use Node.js uses: actions/setup-node@v1 with: - node-version: '16' + node-version: '18' check-latest: true - name: Install yq diff --git a/.github/workflows/release-tracker.yml b/.github/workflows/release-tracker.yml index c0930e6f9b..6a5c55d757 100644 --- a/.github/workflows/release-tracker.yml +++ b/.github/workflows/release-tracker.yml @@ -11,7 +11,8 @@ concurrency: jobs: build: - runs-on: ubuntu-20.04 + name: Build + runs-on: f0 steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a3d2bb7f0c..8b6ae39d0a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,10 +3,7 @@ name: Release on: push: tags: - - "*.*" - schedule: - - cron: '0 0 * * *' - # Allows you to run this workflow manually from the Actions tab + - '*.*' workflow_dispatch: concurrency: @@ -16,22 +13,63 @@ concurrency: jobs: build: name: Build - runs-on: ubuntu-20.04 + runs-on: f0 steps: - uses: actions/checkout@v1 - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ^1.20 - id: go + - name: Check tag matches package version + run: | + PKG_VERSION=$(jq -r '.version' package.json) + GIT_TAG=$(git describe --exact-match --abbrev=0 2>/dev/null || echo "") + test "v${PKG_VERSION}" = "${GIT_TAG}" - - name: Use Node.js - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: - node-version: '16' + node-version: '18' check-latest: true + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Install kubectl + run: | + curl -LO https://dl.k8s.io/release/v1.25.2/bin/linux/amd64/kubectl + chmod +x ./kubectl + sudo mv ./kubectl /usr/local/bin/kubectl + + - name: Install Linode CLI + run: | + python -m pip install --upgrade pip + pip --version + pip install setuptools + pip install linode-cli --upgrade + + - name: Prepare git + env: + GITHUB_USER: 1gtm + GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }} + run: | + set -x + git config --global user.name "${GITHUB_USER}" + git config --global user.email "${GITHUB_USER}@appscode.com" + git config --global \ + url."https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com".insteadOf \ + "https://github.com" + + - name: Install GitHub CLI + run: | + curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1 + sudo mv bin/hub /usr/local/bin + - name: Install yq run: | curl -fsSL -o yqq https://github.com/mikefarah/yq/releases/download/3.3.0/yq_linux_amd64 @@ -50,26 +88,28 @@ jobs: chmod +x hugo-tools sudo mv hugo-tools /usr/local/bin/hugo-tools - - name: Install Firebase CLI + - name: Build run: | - npm i -g firebase-tools@v11.13.0 + npm ci + npm run build - - name: QA + - name: Publish to GitHub Container Registry env: - FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} - GOOGLE_CUSTOM_SEARCH_API_KEY: ${{ secrets.GOOGLE_CUSTOM_SEARCH_API_KEY }} - if: startsWith(github.event.ref, 'refs/tags/') && (contains(github.ref, '-alpha.') || contains(github.ref, '-beta.')) + REGISTRY: ghcr.io/appscode + DOCKER_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }} + USERNAME: 1gtm + GITHUB_USER: 1gtm + GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }} run: | - npm install - make docs - make qa + docker login ghcr.io --username ${USERNAME} --password ${DOCKER_TOKEN} + npm run docker-release - - name: Release + - name: Deploy to QA env: - FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} - GOOGLE_CUSTOM_SEARCH_API_KEY: ${{ secrets.GOOGLE_CUSTOM_SEARCH_API_KEY }} - if: ${{ github.event_name == 'schedule' }} || (startsWith(github.event.ref, 'refs/tags/') && (contains(github.ref, '-alpha.') || contains(github.ref, '-beta.')) == false) + REGISTRY: ghcr.io/appscode + LINODE_CLI_TOKEN: ${{ secrets.LINODE_CLI_TOKEN }} run: | - npm install - make docs - make release + mkdir -p ~/.kube + linode-cli lke kubeconfig-view 19953 --json | jq -r .[0].kubeconfig | base64 -d > ~/.kube/config + kubectl get nodes + make deploy-to-linode diff --git a/.github/workflows/release_old.yml b/.github/workflows/release_old.yml new file mode 100644 index 0000000000..0326f750d4 --- /dev/null +++ b/.github/workflows/release_old.yml @@ -0,0 +1,75 @@ +name: Release_OLD + +on: + push: + tags: + - "*.*" + schedule: + - cron: '0 0 * * *' + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v1 + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.21 + id: go + + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '18' + check-latest: true + + - name: Install yq + run: | + curl -fsSL -o yqq https://github.com/mikefarah/yq/releases/download/3.3.0/yq_linux_amd64 + chmod +x yqq + sudo mv yqq /usr/local/bin/yqq + pip3 install yq + + - name: Install Hugo + run: | + curl -fsSL -o hugo_extended.deb https://github.com/gohugoio/hugo/releases/download/v0.111.1/hugo_extended_0.111.1_linux-amd64.deb + sudo dpkg -i hugo_extended.deb + + - name: Install Hugo Tools + run: | + curl -fsSL -o hugo-tools https://github.com/appscodelabs/hugo-tools/releases/download/v0.2.23/hugo-tools-linux-amd64 + chmod +x hugo-tools + sudo mv hugo-tools /usr/local/bin/hugo-tools + + - name: Install Firebase CLI + run: | + npm i -g firebase-tools@v11.13.0 + + - name: QA + env: + FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} + GOOGLE_CUSTOM_SEARCH_API_KEY: ${{ secrets.GOOGLE_CUSTOM_SEARCH_API_KEY }} + if: startsWith(github.event.ref, 'refs/tags/') && (contains(github.ref, '-alpha.') || contains(github.ref, '-beta.')) + run: | + npm install + make docs + make qa + + - name: Release + env: + FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} + GOOGLE_CUSTOM_SEARCH_API_KEY: ${{ secrets.GOOGLE_CUSTOM_SEARCH_API_KEY }} + if: ${{ github.event_name == 'schedule' }} || (startsWith(github.event.ref, 'refs/tags/') && (contains(github.ref, '-alpha.') || contains(github.ref, '-beta.')) == false) + run: | + npm install + make docs + make release diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..d26578857a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM nginx:1.25-alpine + +ARG TARGETOS +ARG TARGETARCH + +RUN set -x \ + && apk add --update ca-certificates curl + +# Set workdir to the NGINX default dir. +WORKDIR /usr/share/nginx/html + +# Copy HTML from previous build into the Workdir. +COPY public . + +# Expose port 80 +EXPOSE 80/tcp diff --git a/Makefile b/Makefile index 801c837f0b..50553000d9 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,49 @@ +SHELL=/bin/bash -o pipefail + +REGISTRY ?= ghcr.io/appscode +BIN ?= website +IMAGE := $(REGISTRY)/$(BIN) +TAG ?= $(shell git describe --exact-match --abbrev=0 2>/dev/null || echo "") + +DOCKER_PLATFORMS := linux/amd64 linux/arm64 +PLATFORM ?= linux/$(subst x86_64,amd64,$(subst aarch64,arm64,$(shell uname -m))) +VERSION = $(TAG)_$(subst /,_,$(PLATFORM)) + +container-%: + @$(MAKE) container \ + --no-print-directory \ + PLATFORM=$(subst _,/,$*) + +push-%: + @$(MAKE) push \ + --no-print-directory \ + PLATFORM=$(subst _,/,$*) + +all-container: $(addprefix container-, $(subst /,_,$(DOCKER_PLATFORMS))) + +all-push: $(addprefix push-, $(subst /,_,$(DOCKER_PLATFORMS))) + +.PHONY: container +container: gen-prod + @echo "container: $(IMAGE):$(VERSION)" + @docker buildx build --platform $(PLATFORM) --load --pull -t $(IMAGE):$(VERSION) -f Dockerfile . + @echo + +push: container + @docker push $(IMAGE):$(VERSION) + @echo "pushed: $(IMAGE):$(VERSION)" + @echo + +.PHONY: docker-manifest +docker-manifest: + docker manifest create -a $(IMAGE):$(TAG) $(foreach PLATFORM,$(DOCKER_PLATFORMS),$(IMAGE):$(TAG)_$(subst /,_,$(PLATFORM))) + docker manifest push $(IMAGE):$(TAG) + +.PHONY: deploy-to-linode +deploy-to-linode: + kubectl set image -n bb deployment/website ui=$(IMAGE):$(VERSION) + kubectl delete pods -n bb --selector=app.kubernetes.io/name=website" + .PHONY: run run: @yqq w -i config.dev.yaml params.search_api_key --tag '!!str' $(GOOGLE_CUSTOM_SEARCH_API_KEY)