diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..8e62203de85c087c0faaeba1d9213548964e7ca3 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,38 @@ +stages: + - dependencies + - test + - deploy + +.cache: &cache + key: ${CI_COMMIT_REF_SLUG} + paths: + - ./node_modules + +install_dependencies: + cache: + <<: *cache + policy: push + stage: dependencies + image: node + script: + - yarn install +test: + cache: + <<: *cache + policy: pull + stage: test + image: node + script: + - yarn test +deploy: + stage: deploy + image: google/cloud-sdk + services: + - docker:dind + only: + - "main" + script: + - echo $GCP_SERVICE_KEY > gcloud-service-key.json # Google Cloud service accounts + - gcloud auth activate-service-account --key-file gcloud-service-key.json + - gcloud config set project $GCP_PROJECT_ID + - gcloud builds submit . --config=cloudbuild.yml --substitutions=COMMIT_SHA=$CI_COMMIT_SHORT_SHA,_SERVICE_NAME=$GCP_SERVICE_NAME \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c3c01168f42ec51abf3dd3551646a08202a8b3d2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM node:16-alpine3.15 as build-stage + +WORKDIR /app + +COPY . /app + +RUN yarn install +RUN yarn build + +FROM nginx:1.15 +COPY --from=build-stage /app/build/ /usr/share/nginx/html +COPY --from=build-stage /app/nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 8080 \ No newline at end of file diff --git a/cloudbuild.yml b/cloudbuild.yml new file mode 100644 index 0000000000000000000000000000000000000000..bb978d03de4eec76a5415ebe33a165e71b45f8f1 --- /dev/null +++ b/cloudbuild.yml @@ -0,0 +1,22 @@ + steps: + # Build the container image + - name: 'gcr.io/cloud-builders/docker' + args: ['build', '-t', 'gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA', '.'] + # Push the container image to Container Registry + - name: 'gcr.io/cloud-builders/docker' + args: ['push', 'gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA'] + # Deploy container image to Cloud Run + - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' + entrypoint: gcloud + args: + - 'run' + - 'deploy' + - '${_SERVICE_NAME}' + - '--image' + - 'gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA' + - '--region' + - 'us-central1' + - '--platform' + - 'managed' + options: + logging: CLOUD_LOGGING_ONLY \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000000000000000000000000000000000000..399461117d65d59f349b600619f689859c9143cc --- /dev/null +++ b/nginx.conf @@ -0,0 +1,11 @@ +server { + listen 8080; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html =404; + } + + include /etc/nginx/extra-conf.d/*.conf; +} \ No newline at end of file