From 224160971314a541f94270d835eddfe56c63e7c8 Mon Sep 17 00:00:00 2001 From: NishaSharma14 Date: Wed, 18 Oct 2023 14:24:34 +0200 Subject: [PATCH 1/6] build: push image to Docker --- .../workflows/{build.yml => dev-build.yml} | 71 +++++++++++-------- 1 file changed, 41 insertions(+), 30 deletions(-) rename .github/workflows/{build.yml => dev-build.yml} (65%) diff --git a/.github/workflows/build.yml b/.github/workflows/dev-build.yml similarity index 65% rename from .github/workflows/build.yml rename to .github/workflows/dev-build.yml index 29e74086..38990b7c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/dev-build.yml @@ -1,8 +1,12 @@ name : Deploy to Dev +# on: +# push: +# branches: [development] + on: push: - branches: [development] + branches: [issue-#877] env: PROJECT_ID: ${{ secrets.GKE_PROJECT }} @@ -11,9 +15,10 @@ env: DEPLOYMENT_NAME: nmrxiv-nmrxiv-app SCHEDULER_DEPLOYMENT_NAME: nmrxiv-scheduler WORKER_DEPLOYMENT_NAME: nmrxiv-worker - REPOSITORY_NAME: nmrxiv-dev - APP_IMAGE: nmrxiv-app - NGINX_IMAGE: nmrxiv-nginx + DOCKER_HUB_USERNAME : ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD : ${{ secrets.DOCKER_HUB_PASSWORD }} + REPOSITORY_NAME: nmrxiv + REPOSITORY_NAMESPACE: nfdi4chem jobs: php-unit-test: @@ -79,40 +84,46 @@ jobs: service_account_key: ${{ secrets.GKE_SA_KEY }} project_id: ${{ secrets.GKE_PROJECT }} - # Configure docker to use the gcloud command-line tool as a credential helper - - run: |- - gcloud auth configure-docker europe-west3-docker.pkg.dev - # Get the GKE credentials so we can deploy to the cluster + # Get the GKE credentials - uses: google-github-actions/get-gke-credentials@v0.3.0 with: cluster_name: ${{ env.GKE_CLUSTER }} location: ${{ env.GKE_ZONE }} credentials: ${{ secrets.GKE_SA_KEY }} - # Build the Docker image - - name: Build App Image - run: |- - docker build -f ./resources/ops/docker/app/app.dockerfile \ - --tag "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME/$APP_IMAGE:latest" \ - --build-arg GITHUB_SHA="$GITHUB_SHA" \ - --build-arg GITHUB_REF="$GITHUB_REF" \ - . - - name: Build Nginx Image - run: |- - docker build -f ./resources/ops/docker/nginx/nginx.dockerfile \ - --tag "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME/$NGINX_IMAGE:latest" \ - --build-arg GITHUB_SHA="$GITHUB_SHA" \ - --build-arg GITHUB_REF="$GITHUB_REF" \ - . - # Push the Docker image to Google Container Registry - - name: Publish App Image to GCR - run: |- - docker push "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME/$APP_IMAGE:latest" + - name: Log in to Docker Hub + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ${{ env.DOCKER_HUB_USERNAME }} + password: ${{ env.DOCKER_HUB_PASSWORD }} - - name: Publish Nginx Image to GCR - run: |- - docker push "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME/$NGINX_IMAGE:latest" + # Build and push the app Docker image + - name: Build and push App Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./resources/ops/docker/app/app.dockerfile + push: true + build-args: | + RELEASE_VERSION=dev-app-latest + tags: ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:dev-app-latest + username: ${{ env.DOCKER_HUB_USERNAME }} + password: ${{ env.DOCKER_HUB_PASSWORD }} + + # Build and push the nginx Docker image + - name: Build and push Nginx Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./resources/ops/docker/app/app.dockerfile + push: true + build-args: | + RELEASE_VERSION=dev-nginx-latest + tags: ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:dev-nginx-latest + username: ${{ env.DOCKER_HUB_USERNAME }} + password: ${{ env.DOCKER_HUB_PASSWORD }} + # Deploy the latest Docker image to the GKE cluster - name: Deploy run: |- kubectl rollout restart deployment/$DEPLOYMENT_NAME From 5ab3f7e66386c9900d14b6808895053d0633faa5 Mon Sep 17 00:00:00 2001 From: NishaSharma14 Date: Wed, 18 Oct 2023 14:28:37 +0200 Subject: [PATCH 2/6] build: remove github ref --- .github/workflows/dev-build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index 38990b7c..a2e57ca6 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -71,7 +71,6 @@ jobs: setup-build-publish-deploy: name: Build & deploy to development - if: github.ref == 'refs/heads/development' runs-on: ubuntu-latest needs: php-unit-test steps: From 3c82888ec37011d17bcb10b2e887b93a20ff7472 Mon Sep 17 00:00:00 2001 From: NishaSharma14 Date: Wed, 18 Oct 2023 15:04:00 +0200 Subject: [PATCH 3/6] build: update nginx docker imahe build path --- .github/workflows/dev-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index a2e57ca6..80b90955 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -114,7 +114,7 @@ jobs: uses: docker/build-push-action@v4 with: context: . - file: ./resources/ops/docker/app/app.dockerfile + file: ./resources/ops/docker/app/nginx.dockerfile push: true build-args: | RELEASE_VERSION=dev-nginx-latest From f8d448a8a74e282672bc00130ef745e42cba6d4f Mon Sep 17 00:00:00 2001 From: NishaSharma14 Date: Wed, 18 Oct 2023 15:10:45 +0200 Subject: [PATCH 4/6] build: correct nginx image path --- .github/workflows/dev-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index 80b90955..5558416e 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -114,7 +114,7 @@ jobs: uses: docker/build-push-action@v4 with: context: . - file: ./resources/ops/docker/app/nginx.dockerfile + file: ./resources/ops/docker/nginx/nginx.dockerfile push: true build-args: | RELEASE_VERSION=dev-nginx-latest From 6a37e8652a1d090f6f34da1135e5321479283323 Mon Sep 17 00:00:00 2001 From: NishaSharma14 Date: Wed, 18 Oct 2023 15:19:53 +0200 Subject: [PATCH 5/6] fix: push images to Docker Hub --- .github/workflows/dev-build.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index 5558416e..f81dbf89 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -1,12 +1,8 @@ name : Deploy to Dev -# on: -# push: -# branches: [development] - on: push: - branches: [issue-#877] + branches: [development] env: PROJECT_ID: ${{ secrets.GKE_PROJECT }} From aa960ad93f61c01725aabb9eccb9f7960967d463 Mon Sep 17 00:00:00 2001 From: NishaSharma14 Date: Wed, 18 Oct 2023 15:52:08 +0200 Subject: [PATCH 6/6] build: seperate test and invoke on workflow call --- .env.ci.dev => .env.ci.test | 0 .github/workflows/dev-build.yml | 47 +---------------------------- .github/workflows/test.yml | 52 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 46 deletions(-) rename .env.ci.dev => .env.ci.test (100%) create mode 100644 .github/workflows/test.yml diff --git a/.env.ci.dev b/.env.ci.test similarity index 100% rename from .env.ci.dev rename to .env.ci.test diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index f81dbf89..ec89c760 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -18,52 +18,7 @@ env: jobs: php-unit-test: - name: Run test - runs-on: ubuntu-latest - container: - image: kirschbaumdevelopment/laravel-test-runner:8.2 - - services: - postgres: - image: postgres:13 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: nmrxiv - ports: - - 5432:5432 - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - - steps: - - uses: actions/checkout@v1 - with: - fetch-depth: 1 - - - name: Install composer dependencies - run: | - composer install --ignore-platform-reqs - - name: Prepare Laravel Application - run: | - php -r "file_exists('.env') || copy('.env.ci.dev', '.env');" - - echo AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID_DEV }} >> .env - echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }} >> .env - echo MEILISEARCH_KEY=${{ secrets.MEILISEARCH_KEY_DEV }} >> .env - echo MEILISEARCH_PUBLICKEY=${{ secrets.MEILISEARCH_PUBLICKEY_DEV }} >> .env - echo TWITTER_CLIENT_ID=${{ secrets.TWITTER_CLIENT_ID_DEV }} >> .env - echo TWITTER_CLIENT_SECRET=${{ secrets.TWITTER_CLIENT_SECRET_DEV }} >> .env - echo GITHUB_CLIENT_ID=${{ secrets.CLIENT_ID_GITHUB_DEV }} >> .env - echo GITHUB_CLIENT_SECRET=${{ secrets.CLIENT_SECRET_GITHUB_DEV }} >> .env - - php artisan key:generate - php artisan migrate --seed - - name: Install front-end dependencies - run: | - npm install - npm run build - - name: Run Test - run: php artisan test --parallel - + uses: NFDI4Chem/nmrxiv/.github/workflows/test.yml@development setup-build-publish-deploy: name: Build & deploy to development diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..62fdc3d0 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,52 @@ +name : Test + +on: + workflow_call: + +jobs: + php-unit-test: + name: Run test + runs-on: ubuntu-latest + container: + image: kirschbaumdevelopment/laravel-test-runner:8.2 + + services: + postgres: + image: postgres:13 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: nmrxiv + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + + - name: Install composer dependencies + run: | + composer install --ignore-platform-reqs + - name: Prepare Laravel Application + run: | + php -r "file_exists('.env') || copy('.env.ci.test', '.env');" + + echo AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID_DEV }} >> .env + echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }} >> .env + echo MEILISEARCH_KEY=${{ secrets.MEILISEARCH_KEY_DEV }} >> .env + echo MEILISEARCH_PUBLICKEY=${{ secrets.MEILISEARCH_PUBLICKEY_DEV }} >> .env + echo TWITTER_CLIENT_ID=${{ secrets.TWITTER_CLIENT_ID_DEV }} >> .env + echo TWITTER_CLIENT_SECRET=${{ secrets.TWITTER_CLIENT_SECRET_DEV }} >> .env + echo GITHUB_CLIENT_ID=${{ secrets.CLIENT_ID_GITHUB_DEV }} >> .env + echo GITHUB_CLIENT_SECRET=${{ secrets.CLIENT_SECRET_GITHUB_DEV }} >> .env + + php artisan key:generate + php artisan migrate --seed + - name: Install front-end dependencies + run: | + npm install + npm run build + - name: Run Test + run: php artisan test --parallel \ No newline at end of file