From 1ed5eb3e26054eb7e57268c4fddcfc1b9f9f1b89 Mon Sep 17 00:00:00 2001 From: Vojtech Mares Date: Mon, 3 Jul 2023 20:58:23 +0200 Subject: [PATCH] ci: switch from github actions to gitlab ci --- .github/workflows/deploy-to-staging.yml | 129 ------------------------ .gitlab-ci.yml | 67 ++++++++++++ 2 files changed, 67 insertions(+), 129 deletions(-) delete mode 100644 .github/workflows/deploy-to-staging.yml create mode 100644 .gitlab-ci.yml diff --git a/.github/workflows/deploy-to-staging.yml b/.github/workflows/deploy-to-staging.yml deleted file mode 100644 index 7922ae0..0000000 --- a/.github/workflows/deploy-to-staging.yml +++ /dev/null @@ -1,129 +0,0 @@ -name: Deploy to staging from main branch - -on: - push: - branches: - - main - tags-ignore: - - '*' # ignore all tags - -concurrency: - group: deploy-staging - cancel-in-progress: true - -env: - NAMESPACE: backoffice-staging - HELM_VERSION: "3.12.1" - DOCKER_REGISTRY: ghcr.io - DOCKER_IMAGE: vojtechmares/backoffice - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ github.ref }} - - - name: set up qemu - uses: docker/setup-qemu-action@v2 - - - name: set up docker buildx - uses: docker/setup-buildx-action@v2 - - - name: docker login - uses: docker/login-action@v2 - with: - registry: ${{ env.DOCKER_REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: docker meta - id: docker_meta - uses: docker/metadata-action@v4 - with: - tags: | - type=schedule - type=ref,event=branch - type=ref,event=tag - type=ref,event=pr - type=sha,format=long - type=raw,value=${{ github.ref_name }}-${{ github.sha }} - type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - images: | - ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }} - - - name: build and push - uses: docker/build-push-action@v4 - with: - pull: true - push: true - tags: ${{ steps.docker_meta.outputs.tags }} - labels: ${{ steps.docker_meta.outputs.labels }} - # platforms: linux/amd64,linux/arm64,linux/arm/v7 - cache-from: type=registry,ref=${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:latest - - deploy: - runs-on: ubuntu-latest - environment: - name: staging - url: https://staging.backoffice.mareshq.com - needs: - - build - - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ github.ref }} - - # Setup kubectl and Helm for Azure - - uses: azure/setup-helm@v3 - with: - version: "${{ env.HELM_VERSION }}" - - - name: write kube config - run: | - mkdir -p $HOME/.kube/ - echo "${{ secrets.KUBE_CONFIG }}" > $HOME/.kube/config - chmod 600 $HOME/.kube/config - - - name: deploy dry run - run: | - helm upgrade \ - --atomic \ - --wait=true \ - --wait-for-jobs=true \ - --timeout 900s \ - --dry-run=true \ - --install \ - --kube-context="kiwi" \ - --namespace="${{ env.NAMESPACE }}" \ - -f ./charts/backoffice/values.staging.yaml \ - --set image.tag="${{ github.ref_name }}-${{ github.sha }}" \ - --set backoffice.secrets.databaseURL="dummy" \ - --set backoffice.secrets.nextauthSecret="dummy" \ - --set backoffice.secrets.googleClientID="dummy" \ - --set backoffice.secrets.googleClientSecret="dummy" \ - backoffice \ - ./charts/backoffice - - - name: deploy - run: | - helm upgrade \ - --atomic \ - --wait=true \ - --wait-for-jobs=true \ - --timeout 900s \ - --dry-run=true \ - --install \ - --kube-context="kiwi" \ - --namespace="${{ env.NAMESPACE }}" \ - -f ./charts/backoffice/values.staging.yaml \ - --set image.tag="${{ github.ref_name }}-${{ github.sha }}" \ - --set backoffice.secrets.databaseURL="${{ secrets.DATABASE_URL }}" \ - --set backoffice.secrets.nextauthSecret="${{ secrets.NEXTAUTH_SECRET }}" \ - --set backoffice.secrets.googleClientID="${{ secrets.GOOGLE_CLIENT_ID }}" \ - --set backoffice.secrets.googleClientSecret="${{ secrets.GOOGLE_CLIENT_SECRET }}" \ - backoffice \ - ./charts/backoffice diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..e64b8d7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,67 @@ +default: + image: registry.mareshq.com/mareshq/ci-toolkit:latest + +stages: + - build + - deploy + +docker:build: + stage: build + before_script: + - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY + - docker info + script: + - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA . + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA + +deploy:staging:dry-run: + stage: deploy + script: + - > + helm \ + upgrade \ + --install \ + --atomic \ + --wait=true \ + --wait-for-jobs=true \ + --timeout=900s \ + --dry-run=true \ + --namespace backoffice-staging \ + --values ./charts/backoffice/values.staging.yaml \ + --set image.tag=$CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA \ + --set backoffice.secrets.databaseURL=dummy \ + --set backoffice.secrets.nextauthSecret=dummy \ + --set backoffice.secrets.googleClientID=dummy \ + --set backoffice.secrets.googleClientSecret=dummy \ + backoffice \ + ./charts/backoffice + rules: + - if: $CI_COMMIT_BRANCH == "main" + when: always + +deploy:staging: + stage: deploy + script: + - > + helm \ + upgrade \ + --install \ + --atomic \ + --wait=true \ + --wait-for-jobs=true \ + --timeout=900s \ + --namespace backoffice-staging \ + --values ./charts/backoffice/values.staging.yaml \ + --set image.tag=$CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA \ + --set backoffice.secrets.databaseURL=$DATABASE_URL \ + --set backoffice.secrets.nextauthSecret=$NEXTAUTH_SECRET \ + --set backoffice.secrets.googleClientID=$GOOGLE_CLIENT_ID \ + --set backoffice.secrets.googleClientSecret=$GOOGLE_CLIENT_SECRET \ + backoffice \ + ./charts/backoffice + environment: + name: staging + url: https://staging.backoffice.mareshq.com + rules: + - if: $CI_COMMIT_BRANCH == "main" + when: always