From 15447c71a38e68f7d81d27d3d5bd07095acaa14a Mon Sep 17 00:00:00 2001 From: RcleydsonR Date: Wed, 10 Aug 2022 18:25:03 -0300 Subject: [PATCH 1/5] feat: add CD script and remove docker deploy from CI script --- .github/workflows/CD.yml | 43 ++++++++++++++++++++++++++++++++++++++++ .github/workflows/CI.yml | 28 +------------------------- 2 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/CD.yml diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml new file mode 100644 index 00000000..d4b01b39 --- /dev/null +++ b/.github/workflows/CD.yml @@ -0,0 +1,43 @@ +name: CD pipeline + +on: + push : + branches : [ master, develop ] + + +jobs: + deploy: + runs-on: ubuntu-latest + env: + IMAGE_NAME: ${{ secrets.DOCKER_REPOSITORY }}:${{ github.sha }} + FIREBASE_CONFIG_DEV: ${{ secrets.FIREBASE_CONFIG_DEV }} + FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }} + RCLONE_CONFIG: ${{ secrets.RCLONE_CONFIG }} + + steps: + - name: 🏗 Setup repo + uses: actions/checkout@v3 + + - name: 🏗 Config dev files + if: github.ref == 'refs/heads/develop' + run: | + echo "$FIREBASE_CONFIG_DEV" > ./src/config/firebaseAuthConfig.js + echo "$RCLONE_CONFIG" > ./config/rclone.conf + echo "TAG=latest" >> "$GITHUB_ENV" + + - name: 🏗 Config prod files + if: github.ref == 'refs/heads/master' + run: | + echo "$FIREBASE_CONFIG" > ./src/config/firebaseAuthConfig.js + echo "$RCLONE_CONFIG" > ./config/rclone.conf + echo "TAG=stable" >> "$GITHUB_ENV" + + - name: 📦 Docker login + run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_ACCESS_TOKEN }} + + - name: 📦 Docker push image + run: | + docker build . -t "$IMAGE_NAME" + docker push "$IMAGE_NAME" + docker tag "$IMAGE_NAME" ${{ secrets.DOCKER_REPOSITORY }}:"$TAG" + docker push ${{ secrets.DOCKER_REPOSITORY }}:"$TAG" diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 9f8a8e82..99821166 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -37,30 +37,4 @@ jobs: - name: 📦 Run lint run: npx eslint ./src - # Test job - - deploy: - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }} - runs-on: ubuntu-latest - needs: lint - env: - IMAGE_NAME: ${{ secrets.DOCKER_REPOSITORY }}:${{ github.sha }} - - steps: - - name: 🏗 Setup repo - uses: actions/checkout@v3 - - - name: 🏗 Config files - run: | - echo "$FIREBASE_CONFIG_DEV" > ./src/config/firebaseAuthConfig.js - echo "$RCLONE_CONFIG" > ./config/rclone.conf - - - name: 📦 Docker login - run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_ACCESS_TOKEN }} - - - name: 📦 Docker push image - run: | - docker build . -t "$IMAGE_NAME" - docker push "$IMAGE_NAME" - docker tag "$IMAGE_NAME" ${{ secrets.DOCKER_REPOSITORY }}:latest - docker push ${{ secrets.DOCKER_REPOSITORY }}:latest + # Test job From 77e33ece8f9e702c65961d361d7e15cbc135d806 Mon Sep 17 00:00:00 2001 From: RcleydsonR Date: Wed, 10 Aug 2022 18:26:21 -0300 Subject: [PATCH 2/5] fix: remove unnecessary files from repo --- .gitlab-ci.yml | 52 ----------------------------------------- docker-compose.prod.yml | 16 ------------- 2 files changed, 68 deletions(-) delete mode 100644 .gitlab-ci.yml delete mode 100644 docker-compose.prod.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index ae034ee4..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,52 +0,0 @@ -stages: - - lint - - build - -lint: - stage: lint - image: node:12.2.0-alpine - before_script: - - npm install - script: - - npx eslint ./src - allow_failure: true - -build: - services: - - docker:dind - image: docker:stable - stage: build - variables: - IMAGE_NAME: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" - before_script: - - cat $FIREBASE_CONFIG > ./src/config/firebaseAuthConfig.js - - cat $RCLONE_CONFIG > ./config/rclone.conf - script: - - echo "Building image" - - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - - docker build . -t $IMAGE_NAME - - docker push $IMAGE_NAME - - docker tag $IMAGE_NAME $CI_REGISTRY_IMAGE:latest - - docker push $CI_REGISTRY_IMAGE:latest - except: - - master - - configuracao-ci - -build stable: - services: - - docker:dind - image: docker:stable - stage: build - variables: - IMAGE_NAME: "$CI_REGISTRY_IMAGE:stable" - before_script: - - cat $FIREBASE_CONFIG > ./src/config/firebaseAuthConfig.js - - cat $RCLONE_CONFIG > ./config/rclone.conf - script: - - echo "Building image" - - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - - docker build . -t $IMAGE_NAME - - docker push $IMAGE_NAME - only: - - master - - configuracao-ci diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml deleted file mode 100644 index da9e7594..00000000 --- a/docker-compose.prod.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: "3" -services: - mgob: - container_name: mgob - environment: - - MONGODB_USERNAME=${MONGODB_USERNAME} - - MONGODB_PASSWORD=${MONGODB_PASSWORD} - image: stefanprodan/mgob:edge - command: ./mgob -LogLevel=info - volumes: - - ./config:/config - - /mgob/storage:/storage - - /mgob/tmp:/tmp - - /mgob/data:/data - depends_on: - - mongo From 3dae5d5ab12988d2ef257e90a77428b1236d5630 Mon Sep 17 00:00:00 2001 From: RcleydsonR Date: Tue, 23 Aug 2022 17:08:10 -0300 Subject: [PATCH 3/5] fix: remove matrix version from CI script because it depends on docker version (lts) --- .github/workflows/CI.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 99821166..7e8ccb65 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -9,9 +9,6 @@ on: jobs: lint: runs-on: ubuntu-latest - strategy: - matrix: - node: [ 14, 16 ] defaults: run: shell: bash @@ -23,7 +20,7 @@ jobs: - name: 🏗 Setup node uses: actions/setup-node@v3 with: - node-version: ${{ matrix.node }} + node-version: lts/* cache: yarn cache-dependency-path: yarn.lock From 6849e2535e3e95378419dbb80cfcc31ffdc51bd1 Mon Sep 17 00:00:00 2001 From: RcleydsonR Date: Tue, 23 Aug 2022 22:23:58 -0300 Subject: [PATCH 4/5] feat: add test step in CI script --- .github/workflows/CI.yml | 13 ++++++++----- package.json | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7e8ccb65..2cf4b8d8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -7,7 +7,7 @@ on: types: [ opened ] jobs: - lint: + test-lint: runs-on: ubuntu-latest defaults: run: @@ -27,11 +27,14 @@ jobs: - name: 🏗 Config files run: | echo "$FIREBASE_CONFIG_DEV" > ./src/config/firebaseAuthConfig.js - + env: + FIREBASE_CONFIG_DEV: ${{ secrets.FIREBASE_CONFIG_DEV }} + - name: 📦 Install dependencies run: yarn install --pure-lockfile --non-interactive - - name: 📦 Run lint - run: npx eslint ./src + - name: 📦 Run test + run: yarn test - # Test job + - name: 📦 Run lint + run: yarn lint diff --git a/package.json b/package.json index 247fd219..8d480ff0 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "start:dev": "nodemon index.js", "dev": "node server.js", "test": "jest", - "test:coverage": "jest --coverage" + "test:coverage": "jest --coverage", + "lint": "npx eslint ./src", + "lint:fix": "npx eslint ./src --fix" }, "dependencies": { "@sentry/node": "5.18.0", From 6cda62b0b1cdc692bb17134672b5dc4374a4aec0 Mon Sep 17 00:00:00 2001 From: RcleydsonR Date: Thu, 25 Aug 2022 01:01:39 -0300 Subject: [PATCH 5/5] fix: rename workflow files --- .github/workflows/{CI.yml => build.yml} | 4 ++-- .github/workflows/{CD.yml => submit.yml} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{CI.yml => build.yml} (95%) rename .github/workflows/{CD.yml => submit.yml} (97%) diff --git a/.github/workflows/CI.yml b/.github/workflows/build.yml similarity index 95% rename from .github/workflows/CI.yml rename to .github/workflows/build.yml index 2cf4b8d8..b83186fe 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: CI pipeline +name: build, test and lint on: push : @@ -7,7 +7,7 @@ on: types: [ opened ] jobs: - test-lint: + build-test: runs-on: ubuntu-latest defaults: run: diff --git a/.github/workflows/CD.yml b/.github/workflows/submit.yml similarity index 97% rename from .github/workflows/CD.yml rename to .github/workflows/submit.yml index d4b01b39..a59c1fe7 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/submit.yml @@ -1,4 +1,4 @@ -name: CD pipeline +name: submit image to dockerhub on: push :