From 8bf7855c6d81d533ec7ab1ad4b82f1b0e697faeb Mon Sep 17 00:00:00 2001 From: bombnp Date: Sun, 21 Jul 2024 12:55:55 +0700 Subject: [PATCH] feat: add workflow --- .github/workflows/deploy.yaml | 48 +++++++++++++++++++++++++++++++++++ Dockerfile | 32 +++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 .github/workflows/deploy.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..35cb63d --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,48 @@ +name: Deployment + +on: + push: + branches: [main] + workflow_dispatch: + +permissions: + id-token: write + contents: read + packages: write + +concurrency: + group: deploy + cancel-in-progress: false + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + - name: buildx + uses: docker/setup-buildx-action@v2 + - name: login + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: build + id: build-and-push + uses: docker/build-push-action@v3 + with: + push: true + tags: ghcr.io/webmastercamp/${{ github.event.repository.name }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Deploy to deploys.app + uses: deploys-app/deploys-action@v1 + with: + project: webmastercamp-jwc13 + location: gke.cluster-rcf2 + name: ${{ github.event.repository.name }} + image: ghcr.io/webmastercamp/${{ github.event.repository.name }}:latest + env: + DEPLOYS_AUTH_USER: ${{ secrets.DEPLOYS_AUTH_USER }} + DEPLOYS_AUTH_PASS: ${{ secrets.DEPLOYS_AUTH_PASS }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..13ee6cf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM node:20-alpine as deps + +WORKDIR /app + +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ + else echo "Lockfile not found." && exit 1; \ + fi + +COPY . ./ + +FROM deps as builder +WORKDIR /app + +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +RUN \ + if [ -f yarn.lock ]; then yarn run build; \ + elif [ -f package-lock.json ]; then npm run build; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ + else echo "Lockfile not found." && exit 1; \ + fi + +FROM nginx:latest as prod + +COPY --from=builder /app/dist /usr/share/nginx/html + +CMD ["nginx", "-g", "daemon off;"]