From 31c3f9c3c60e6a87b4e7f0740de35e18c8793f04 Mon Sep 17 00:00:00 2001 From: Oleksandr Varchenko Date: Thu, 21 Nov 2024 15:51:57 +0200 Subject: [PATCH] Migrate CI to skaffold --- .github/workflows/actions.yaml | 27 ++++++++++++++++--------- .github/workflows/tag.yaml | 26 +++++++++++++++--------- Dockerfile | 35 +++++++++++++++------------------ skaffold.yaml | 5 +++++ werf.yaml | 36 ---------------------------------- 5 files changed, 56 insertions(+), 73 deletions(-) create mode 100644 skaffold.yaml delete mode 100644 werf.yaml diff --git a/.github/workflows/actions.yaml b/.github/workflows/actions.yaml index a6cbf27..28f12a4 100644 --- a/.github/workflows/actions.yaml +++ b/.github/workflows/actions.yaml @@ -2,6 +2,7 @@ on: push: branches: - 'master' + - 'feature/migrate-ci-to-skaffold' jobs: converge: @@ -21,17 +22,25 @@ jobs: # This is where you will update the personal access token to GITHUB_TOKEN run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin - - name: Run echo - run: | - werf version - docker version - echo $GITHUB_REPOSITORY - echo $GITHUB_SHA - - name: Run Build + - name: Cache layers + uses: actions/cache@v3 + with: + path: "${{ github.workspace }}/.skaffold/cache" + key: skaffold-${{ hashFiles('**/cache') }} + restore-keys: | + skaffold- + + - name: Set up environment variables run: | - . $(werf ci-env github --as-file) echo "${{ secrets.STAGE_ENV }}" > .env.deploy - werf export web --tag ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA --dev + + - name: Run Skaffold pipeline as command + uses: hiberbee/github-action-skaffold@latest + id: build + with: + command: build --tag ${{ github.sha }} + repository: ghcr.io/${{ github.repository_owner }} + stage-deploy: name: Deploy on stage needs: converge diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml index 1e81fa3..05df9c0 100644 --- a/.github/workflows/tag.yaml +++ b/.github/workflows/tag.yaml @@ -21,17 +21,25 @@ jobs: # This is where you will update the personal access token to GITHUB_TOKEN run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin - - name: Run echo - run: | - werf version - docker version - echo $GITHUB_REPOSITORY - echo $GITHUB_REF_NAME - - name: Run Build + - name: Cache layers + uses: actions/cache@v3 + with: + path: "${{ github.workspace }}/.skaffold/cache" + key: skaffold-${{ hashFiles('**/cache') }} + restore-keys: | + skaffold- + + - name: Set up environment variables run: | - . $(werf ci-env github --as-file) echo "${{ secrets.PROD_ENV }}" > .env.deploy - werf export web --tag ghcr.io/$GITHUB_REPOSITORY:$GITHUB_REF_NAME --dev + + - name: Run Skaffold pipeline as command + uses: hiberbee/github-action-skaffold@latest + id: build + with: + command: build --tag ${{ github.ref_name }} + repository: ghcr.io/${{ github.repository_owner }} + prod-deploy: name: Deploy on prod needs: converge diff --git a/Dockerfile b/Dockerfile index b9a7701..71b0272 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,19 @@ -FROM node:14-alpine3.11 as builder -RUN apk --no-cache --update --virtual build-dependencies add \ - python \ - make \ - g++ - -ARG BUILD_VERSION -WORKDIR /dist -COPY package*.json ./ -COPY yarn*.lock ./ -RUN true \ - && yarn autoclean --init \ - && yarn autoclean --force \ - && yarn install \ - && true +FROM node:18-alpine AS builder + +RUN apk --no-cache --update --virtual build-dependencies add python3 make g++ + +WORKDIR /frontend + +COPY package.json yarn.lock ./ + +RUN yarn install + COPY . . -RUN yarn lint | tee 1.log | sed -e 's/^/[yarn lint] /' & yarn test | tee 2.log | sed -e 's/^/[yarn test] /' & yarn build --set-build-version "$BUILD_VERSION" | tee 3.log | sed -e 's/^/[yarn build] /' -FROM nginx:1.20.2-alpine +RUN yarn generate --dotenv .env.deploy + +FROM nginx:alpine + COPY nginx.conf /etc/nginx/nginx.conf -COPY --from=builder /build/dist /usr/share/nginx/html -CMD ["nginx", "-g", "daemon off;"] + +COPY --from=builder /frontend/.output/public /usr/share/nginx/html \ No newline at end of file diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 0000000..b53ec93 --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,5 @@ +apiVersion: skaffold/v2beta28 +kind: Config +build: + artifacts: + - image: frontend \ No newline at end of file diff --git a/werf.yaml b/werf.yaml deleted file mode 100644 index 486d775..0000000 --- a/werf.yaml +++ /dev/null @@ -1,36 +0,0 @@ -configVersion: 1 -project: "web-client" ---- -image: builder -from: node:18-alpine -git: - - add: / - to: /frontend - stageDependencies: - install: - - package.json - - yarn.lock - setup: - - "**/*" -shell: - beforeInstall: - - apk --no-cache --update --virtual build-dependencies add python3 make g++ - install: - - cd /frontend - #- yarn autoclean --init - #- yarn autoclean --force - - yarn install - setup: - - cd /frontend - - yarn generate --dotenv .env.deploy ---- -image: web -from: nginx:alpine -git: - - add: /nginx.conf - to: /etc/nginx/nginx.conf -import: - - image: builder - add: /frontend/.output/public - to: /usr/share/nginx/html - after: setup