From 680db6bbecdd8e21c28ad717488cc8d6e6a0df3d Mon Sep 17 00:00:00 2001 From: skeris Date: Sun, 5 Jan 2025 02:11:15 +0300 Subject: [PATCH] ci: deployment rules WIP --- .gitea/workflows/deploy.yml | 24 ++++++++++++ .gitea/workflows/lint.yml | 14 +++++++ .gitlab-ci.yml | 29 --------------- Dockerfile | 73 ++++++------------------------------- 4 files changed, 50 insertions(+), 90 deletions(-) create mode 100644 .gitea/workflows/deploy.yml create mode 100644 .gitea/workflows/lint.yml delete mode 100644 .gitlab-ci.yml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..5d17c60 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,24 @@ +name: Deploy +run-name: ${{ gitea.actor }} build image and push to container registry + +on: + push: + branches: + - 'main' + - 'staging' + +jobs: + CreateImage: + runs-on: [hubstaging] + uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/build-image.yml@v1.1.6-p + with: + runner: hubstaging + secrets: + REGISTRY_USER: ${{ secrets.REGISTRY_USER }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + DeployService: + runs-on: [hubstaging] + needs: CreateImage + uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/deploy.yml@v1.1.4-p7 + with: + runner: hubstaging diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml new file mode 100644 index 0000000..0bd7867 --- /dev/null +++ b/.gitea/workflows/lint.yml @@ -0,0 +1,14 @@ +name: Lint +run-name: ${{ gitea.actor }} produce linting + +on: + push: + branches: + - 'dev' + +jobs: + Lint: + runs-on: [hubstaging] + uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/lint.yml@v1.1.2 + with: + runner: hubstaging diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 8f8efc4..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,29 +0,0 @@ -include: - - project: "devops/pena-continuous-integration" - file: "/templates/docker/build-template.gitlab-ci.yml" - - project: "devops/pena-continuous-integration" - file: "/templates/docker/deploy-template.gitlab-ci.yml" - -build-app: - stage: build - tags: - - nodebuild - extends: .build_template - variables: - DOCKER_BUILD_PATH: "./Dockerfile" - PRODUCTION_BRANCH: main - STAGING_BRANCH: staging - -deploy-to-staging: - tags: - - staging - rules: - - if: "$CI_COMMIT_BRANCH == $STAGING_BRANCH" - extends: .deploy_template - -deploy-to-prod: - rules: - - if: "$CI_COMMIT_BRANCH == $PRODUCTION_BRANCH" - tags: - - prod - extends: .deploy_template diff --git a/Dockerfile b/Dockerfile index 2ce2d0c..9ce2af3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,64 +1,15 @@ -FROM node:20.5.1-alpine3.17 as build - -# Update packages and clear cache -RUN apk update && rm -rf /var/cache/apk/* -# Set the working directory inside the container +FROM gitea.pena/penadevops/container-images/golang:main as build WORKDIR /app -# Add package metadata files -ADD yarn.lock package.json tsconfig.json ./ -# Add src folder -ADD src ./src/ -# Add tools -ADD tools ./tools/ -# Add migrations -ADD migrations ./migrations -# Install packages -RUN yarn install --ignore-scripts --non-interactive && yarn cache clean -# Build app -RUN yarn build +ENV GOPRIVATE=gitea.pena/PenaSide/common,gitea.pena/PenaSide/linters-golang,gitea.pena/PenaSide/customer,gitea.pena/PenaSide/trashlog,gitea.pena/PenaSide/hlog +ENV GOINSECURE=gitea.pena/PenaSide/common,gitea.pena/PenaSide/linters-golang,gitea.pena/PenaSide/customer,gitea.pena/PenaSide/trashlog,gitea.pena/PenaSide/hlog +ENV GOPROXY=https://proxy.golang.org,direct +ENV GOPATH=go-cache +COPY . . +RUN go mod download +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app +FROM gitea.pena/penadevops/container-images/alpine:main +RUN apk add --no-cache ca-certificates +COPY --from=build app/app . +CMD ["/app"] - -FROM node:20.5.1-alpine3.17 as test - -# Update packages and clear cache -RUN apk update && rm -rf /var/cache/apk/* -# Set production env -ENV NODE_ENV=production -# Set the working directory inside the container -WORKDIR /app -# Copy built files from build stage -COPY --from=build /app/dist /app/package.json /app/yarn.lock ./ -# Copy migrate tool from build stage -COPY --from=build /app/tools/migrate /usr/local/bin/migrate -# Copy test migrations from build stage -COPY --from=build /app/migrations/test ./migrations -# Change ownership of files in the /app directory to the 'node' user -RUN chown -R node: . -# Install packages -RUN yarn install --non-interactive --frozen-lockfile --production && yarn cache clean -# Set 'node' user as the active user within the container -USER node -# Run the Node.js application -CMD ["node", "./index.js"] - - - -FROM node:20.5.1-alpine3.17 as production - -# Update packages and clear cache -RUN apk update && rm -rf /var/cache/apk/* -# Set production env -ENV NODE_ENV=production -# Set the working directory inside the container -WORKDIR /app -# Copy built files from build stage -COPY --from=build /app/dist /app/package.json /app/yarn.lock ./ -# Change ownership of files in the /app directory to the 'node' user -RUN chown -R node: . -# Install packages -RUN yarn install --non-interactive --frozen-lockfile --production && yarn cache clean -# Set 'node' user as the active user within the container -USER node -# Run the Node.js application -CMD ["node", "./index.js"] \ No newline at end of file