Browse Source

👷 Setup ci / cd for main branch

👷 Setup ci / cd for main branch
main
Anthony Quéré 5 years ago
committed by GitHub
parent
commit
172792f0e0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 171
      .circleci/config.yml
  2. 17
      Dockerfile

171
.circleci/config.yml

@ -0,0 +1,171 @@
version: 2.1
# --- Constants --- #
globals:
images:
node: &node cimg/node:lts
caches:
dependencies: &dependencies dependencies-{{ checksum "package.json" }}
docker_hub:
user-id: &dockerhub-user-id anthonyjhoiro
password: &dockerhub-password $DOCKERHUB_PASSWORD
image: &dockerhub-image devops-tpfinal-front
backends:
prod: &prod-backend-url https://tpfinal-devops-back.herokuapp.com
# --- Commands --- #
commands:
setup_dependencies:
description: Setup the environment
steps:
- checkout
- restore_cache:
keys:
- *dependencies
# --- Jobs definitions --- #
jobs:
build: &shared-config
docker:
- image: *node
auth:
username: *dockerhub-user-id
password: *dockerhub-password
working_directory: ~/app
steps:
- checkout
- restore_cache:
keys:
- *dependencies
# fallback to using the latest cache if no exact match is found
- dependencies-
- run: yarn install
- save_cache:
paths:
- node_modules
key: *dependencies
test:
<<: *shared-config
steps:
- setup_dependencies
- run: yarn test:unit
lint:
<<: *shared-config
steps:
- setup_dependencies
- run:
name: Check files format
command: yarn format:write
- run:
name: Lint files
command: yarn format:check
docker-build:
<<: *shared-config
parameters:
backendurl:
type: string
environment:
DOCKER_HUB_PWD: *dockerhub-password
DOCKER_HUB_USER_ID: *dockerhub-user-id
DOCKER_HUB_IMAGE: *dockerhub-image
steps:
- checkout
- setup_remote_docker:
version: 20.10.7
- run:
name: Build docker image
command: |
docker build -t app --build-arg backend_url=<<parameters.backendurl>> .
- deploy:
name: Publish image to Docker Hub
command: |
echo $DOCKERHUB_PASSWORD | docker login -u $DOCKER_HUB_USER_ID --password-stdin
docker tag app $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:$CIRCLE_BUILD_NUM
docker tag app $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:latest
docker push $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:$CIRCLE_BUILD_NUM
docker push $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:latest
build-netlify:
<<: *shared-config
parameters:
backendurl:
type: string
environment:
VITE_BACKEND_URL_URL: <<parameters.backendurl>>
steps:
- setup_dependencies
- run: yarn build
- run:
name: Copy deployment artifacts to workspace
command: |
cp -r dist/ /tmp/build
- store_artifacts:
path: /tmp/build
- persist_to_workspace:
root: /tmp
paths:
- build
deploy-netlify:
<<: *shared-config
working_directory: ~/todoapp
steps:
- attach_workspace:
at: /tmp
- run:
name: Install netlify
command: yarn add -D netlify-cli
- run:
name: Deploy app
command: yarn netlify deploy --prod --dir=/tmp/build
# --- Workflow definition --- #
workflows:
version: 2
build-test-and-lint:
jobs:
- build
- test:
requires:
- build
- lint:
requires:
- build
- build-netlify:
backendurl: *prod-backend-url
requires:
- test
- lint
filters:
branches:
only:
- main
- deploy-netlify:
requires:
- build-netlify
filters:
branches:
only:
- main
- docker-build:
backendurl: *prod-backend-url
requires:
- test
- lint
filters:
branches:
only:
- main

17
Dockerfile

@ -0,0 +1,17 @@
FROM node:lts as builder
WORKDIR /build
ARG backend_url
ENV VITE_BACKEND_URL_URL=$backend_url
COPY . .
RUN yarn install
RUN yarn build
FROM nginx:stable
WORKDIR /usr/share/nginx/html
COPY --from=builder /build/dist .
Loading…
Cancel
Save