diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..0bfacb33 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +/build +Makefile +README.md +compose.yml +/.git diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..96807a26 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,46 @@ +include: + - project: "devops/pena-continuous-integration" + file: "/templates/docker/build-template.gitlab-ci.yml" + - project: "devops/pena-continuous-integration" + file: "/templates/docker/clean-template.gitlab-ci.yml" + - project: "devops/pena-continuous-integration" + file: "/templates/docker/deploy-template.gitlab-ci.yml" +stages: + - clean + - build + - deploy + +clear-old-images: + extends: .clean_template + variables: + STAGING_BRANCH: "main" + PRODUCTION_BRANCH: "main" + image: + name: docker/compose:1.28.0 + entrypoint: [""] + before_script: + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker images + script: + - docker system prune -af +build-app: + extends: .build_template + variables: + DOCKER_BUILD_PATH: "./Dockerfile" + STAGING_BRANCH: "main" + PRODUCTION_BRANCH: "main" + script: + - mkdir -p /kaniko/.docker + - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json + - | + /kaniko/executor --context $CI_PROJECT_DIR \ + --cache=true --cache-repo=$CI_REGISTRY_IMAGE \ + --dockerfile $CI_PROJECT_DIR/$DOCKER_BUILD_PATH --use-new-run --snapshotMode=redo \ + --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID + +deploy-to-staging: + extends: .deploy_template + variables: + DEPLOY_TO: "staging" + BRANCH: "main" + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..96084d0b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM node:19.1-alpine as build + +RUN apk update && rm -rf /var/cache/apk/* +WORKDIR /usr/app +COPY . . + +RUN yarn install --ignore-scripts --non-interactive --frozen-lockfile && yarn cache clean +RUN yarn build + + +FROM nginx:latest as result +WORKDIR /usr/share/nginx/html +COPY --from=build /usr/app/build/ /usr/share/nginx/html +COPY hub.conf /etc/nginx/conf.d/default.conf diff --git a/deployments/staging/docker-compose.yaml b/deployments/staging/docker-compose.yaml new file mode 100644 index 00000000..4a851e2b --- /dev/null +++ b/deployments/staging/docker-compose.yaml @@ -0,0 +1,13 @@ +services: + squiz: + container_name: squiz + restart: unless-stopped + image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID + networks: + - marketplace_penahub_frontend + hostname: squiz + tty: true +networks: + marketplace_penahub_frontend: + external: true +