diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..4cb2fdb --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,89 @@ +name: Slender keeper CI +on: + push: + workflow_dispatch: + +env: + IMAGE_NAME: ${{ github.repository }} + REGISTRY: ${{ vars.REGISTRY }} + LIMIT_CPU: "500m" + LIMIT_MEMORY: "512Mi" + +jobs: + build-image-app: + runs-on: ubuntu-latest + outputs: + output_tag: ${{ steps.tag_env.outputs.tag }} + steps: + - uses: actions/checkout@v4 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ vars.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,enable=true,priority=600,prefix=,suffix=-{{date 'YYYYMMDD'}}-{{sha}},event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'deploy') }} + - id: tag_env + run: echo "tag=${{ env.DOCKER_METADATA_OUTPUT_VERSION }}" >> $GITHUB_OUTPUT + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + deploy-app-slender-stage: + needs: build-image-app + env: + SERVICE_NAME: ${{ vars.APP_NAME }} + NAMESPACE: ${{ vars.NAMESPACE}}-stage + runs-on: 'ubuntu-latest' + steps: + - uses: azure/setup-kubectl@v3 + with: + version: 'v1.27.1' + id: install + - uses: azure/setup-helm@v3 + with: + version: 'v3.12.0' + - name: 'Clone Helm repository' + uses: actions/checkout@v3 + with: + repository: ${{ vars.HELM_REPOSITORY }} + ref: 'main' + token: ${{ secrets.PAT }} + - name: 'Prep extraEnv' + run: | + cat < extraEnv.yml + ${{ vars.EXTRA_ENV_FILE }} + EOF + - name: Set Kubernetes Context + uses: azure/k8s-set-context@v3 + with: + method: kubeconfig + kubeconfig: ${{ secrets.KUBECONFIG }} + context: ${{ env.CLUSTER }} + - name: Deploy + run: | + helm upgrade \ + -i ${{ env.SERVICE_NAME }} \ + -n ${{ env.NAMESPACE }} \ + --set nameOverride=${{ env.SERVICE_NAME }} \ + --set imagePullSecrets[0].name=${{ vars.GH_SECR }}\ + --set image.repository=${{ env.REGISTRY }} \ + --set image.name=${{ env.IMAGE_NAME }} \ + --set image.tag=${{ needs.build-image-app.outputs.output_tag }} \ + --set resources.limits.cpu=${{ env.LIMIT_CPU }} \ + --set resources.limits.memory=${{ env.LIMIT_MEMORY }} \ + -f extraEnv.yml \ + ./ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..df22b7a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM node:20-slim as build +WORKDIR /build +COPY . . +RUN yarn install --frozen-lockfile +RUN yarn build + +FROM node:20-slim +WORKDIR /app +COPY --from=build ["/build/node_modules", "node_modules/"] +COPY --from=build ["/build/dist", "dist/"] +COPY --from=build ["/build/package.json", "./"] +CMD ["yarn", "start"]