Skip to content

Commit

Permalink
fix: build and push docker image to Docker Hub
Browse files Browse the repository at this point in the history
refactoring of test files
  • Loading branch information
NishaSharma14 committed Oct 24, 2023
1 parent 5854182 commit 85004c2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 35 deletions.
61 changes: 26 additions & 35 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,20 @@ env:
GKE_CLUSTER_DEV: nmrxiv-dev
GKE_ZONE: europe-west3-a
DEPLOYMENT_NAME: nodejs-nmrxiv-nodejs-microservice
REPOSITORY_NAME_DEV: nmrxiv-dev
IMAGE: nmrxiv-nodejs-microservice
DOCKER_HUB_USERNAME : ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD : ${{ secrets.DOCKER_HUB_PASSWORD }}
REPOSITORY_NAME: nodejs-microservice
REPOSITORY_NAMESPACE: nfdi4chem

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: 'Create .env file'
run: |
touch .env
cp .env.example .env
- run: npm ci
- run: npm run build --if-present
- name: Install Playwright
run: npx playwright install --with-deps
- name: Run test
run: npm test
e2etest:
uses: NFDI4Chem/nmrxiv-nodejs-microservice/.github/workflows/e2e.yml@development

setup-build-publish-deploy-dev:
name: Deploy to dev
if: github.ref == 'refs/heads/development'
runs-on: ubuntu-latest
needs: test
needs: e2etest
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -69,23 +50,33 @@ jobs:
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
- name: Get GKE credentials
uses: google-github-actions/[email protected]
with:
cluster_name: ${{ env.GKE_CLUSTER_DEV }}
location: ${{ env.GKE_ZONE }}
credentials: ${{ secrets.GKE_SA_KEY }}

# Build the Docker image
- name: Build docker image
run: |-
docker build --tag europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME_DEV/$IMAGE:latest .
# Login to Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ env.DOCKER_HUB_PASSWORD }}

# Push the Docker image to Google Artifact Registry
- name: Publish Image to Google Artifact Registry
run: |-
docker push "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME_DEV/$IMAGE:latest"
# Build and push image to Docker Hub
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
build-args: |
RELEASE_VERSION=dev-latest
tags: ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:dev-latest
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ env.DOCKER_HUB_PASSWORD }}

# Deploy the latest Docker image to the GKE cluster
- name: Deploy
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: e2e tests

on:
workflow_call:

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: 'Create .env file'
run: |
touch .env
cp .env.example .env
- run: npm ci
- run: npm run build --if-present
- name: Install Playwright
run: npx playwright install --with-deps
- name: Run test
run: npm test

0 comments on commit 85004c2

Please sign in to comment.