Skip to content
Snippets Groups Projects
Commit 0bf4b761 authored by Arie Peterson's avatar Arie Peterson
Browse files

Building and deploying from CI

parent a1ee18e8
No related branches found
No related tags found
1 merge request!10Resolve "Deploy to hosting platform"
stages: stages:
- build-container
- test - test
- build - build
- deploy
variables:
IMAGENAME: helpful-contact-form-builder
# Use this image unless specified otherwise. Note that this image is actually
# built by the build-container job.
default:
image: "${CI_REGISTRY_IMAGE}/${IMAGENAME}:${CI_COMMIT_REF_NAME}"
build-container:
stage: build-container
image:
# We need a shell to provide the registry credentials, so we need to use the
# kaniko debug image (https://github.com/GoogleContainerTools/kaniko#debug-image)
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --cache=true --context ${CI_PROJECT_DIR}/ --dockerfile ${CI_PROJECT_DIR}/build.Dockerfile --destination ${CI_REGISTRY_IMAGE}/${IMAGENAME}:${CI_COMMIT_REF_NAME}
test: test:
stage: test stage: test
image: node:15-buster-slim
cache: cache:
key: "pnpm-cache" key: "pnpm-cache"
paths: paths:
- "$CI_PROJECT_DIR/.pnpm-store" - "$CI_PROJECT_DIR/.pnpm-store"
before_script: before_script:
- npm install -g pnpm
- pnpm install
- pnpm install -g js-yaml jest - pnpm install -g js-yaml jest
script: script:
- jest src/ --coverage --coverageReporters cobertura - jest src/ --coverage --coverageReporters cobertura
...@@ -18,3 +37,30 @@ test: ...@@ -18,3 +37,30 @@ test:
artifacts: artifacts:
reports: reports:
cobertura: "$CI_PROJECT_DIR/coverage/cobertura-coverage.xml" cobertura: "$CI_PROJECT_DIR/coverage/cobertura-coverage.xml"
build:
stage: build
script:
- npm build
artifacts:
paths:
- build
# Deploy main branch to contact.greenhost.net
deploy-production-net:
stage: deploy
environment:
name: production
url: https://contact.greenhost.net
variables:
ENVIRONMENT: 'production'
FTP_USER: 'webmaster_greenhost_nl'
FTP_HOST: 'ftp.greenhost.nl'
DOMAIN_NAME: 'greenhost.net'
SUBDOMAIN: 'contact'
BUILD_FOLDER: './build'
# TODO: commented out for testing
# rules:
# - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- deploy/deploy.sh
FROM node:15-buster-slim
RUN npm install -g pnpm
WORKDIR /workspaces/outage-form
ENV PATH $PATH:/workspaces/outage-form/node_modules/.bin
RUN pnpm install
#!/bin/bash
set -euvo pipefail
# Run ssh-agent and add ssh key.
eval $(ssh-agent -s)
ssh-add <(echo "$SSH_KEY")
# Add server's ssh host key to known hosts.
mkdir -p ~/.ssh
[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts
sshHost="${FTP_USER}@${FTP_HOST}"
targetDir='${HOME}'"${DOMAIN_NAME}/${SUBDOMAIN}"
rsyncTarget="${sshHost}:${targetDir}"
# Upload site.
# rsync -HAXa --delete ${BUILD_FOLDER}/ "${rsyncTarget}"
# TODO: dry run for testing
rsync -HAXa --delete ${BUILD_FOLDER}/ "${rsyncTarget}" --dry-run
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment