diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6e9a5c55004306f4b8aa986f8b1c5515e21dc328..4d0527f6c280375cba1dfd3c08bf4eb31ac913ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,17 +1,78 @@ image: "node:lts-alpine" -before_script: - - nodejs -v +stages: + - install + - test + - build + - sync + - destroy -lint: - stage: test +install:yarn: + stage: install script: - - export NODE_ENV="CI" - yarn install --frozen-lockfile - - yarn lint --no-fix + cache: + paths: + - node_modules/ + artifacts: + paths: + - node_modules/ + expire_in: 1d + +.dep:yarn: + needs: + - install:yarn + dependencies: + - install:yarn + +lint: + extends: + - .dep:yarn + stage: test + variables: + NODE_ENV: "CI" + script: yarn lint --no-fix test:unit: + extends: + - .dep:yarn stage: test + script: yarn test:unit + +build:yarn: + extends: + - .dep:yarn + stage: build + script: yarn build + artifacts: + paths: + - dist + expire_in: 1d + +sync:s3: + image: + name: banst/awscli + entrypoint: [""] + stage: sync + dependencies: + - build:yarn + needs: + - build:yarn script: - - yarn install --frozen-lockfile - - yarn test:unit + - deploy/s3_setup + - deploy/s3_sync + only: + variables: + - $S3_BUCKET_NAME && $AWS_ACCESS_KEY_ID && $AWS_ACCESS_KEY_ID + +destroy:s3: + image: + name: banst/awscli + entrypoint: [""] + stage: destroy + when: manual + script: + - yes | deploy/s3_teardown || true + only: + variables: + - $S3_BUCKET_NAME && $AWS_ACCESS_KEY_ID && $AWS_ACCESS_KEY_ID diff --git a/README.md b/README.md index 1d8169282f847e222c4dde94ae0903fe3636d3cb..84470b20f1e561f77211f3103f9c9333ab9604ad 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ See [Configuration Reference](https://cli.vuejs.org/config/). ## Deployment to AWS S3 +### From your local machine + The folder `deploy/` contains 3 scripts which take care of deploying this project to AWS S3 locally: * `deploy/build_project` - Build this project * `deploy/s3_setup` - Create a S3 bucket (if not preexisting) and configure it as a [website](https://docs.aws.amazon.com/AmazonS3/latest/dev/HostingWebsiteOnS3Setup.html) @@ -70,3 +72,20 @@ export AWS_ACCESS_KEY_ID="AKIA3XKX1672T6TP5VM3" export AWS_SECRET_ACCESS_KEY="JVmVBmpzygF/fEWYL1ydThUzdhzuLg8rLwfXYpst" export AWS_DEFAULT_REGION="us-west-1" # https://docs.aws.amazon.com/general/latest/gr/rande.html ``` + +### From CI pipeline + +In order to deploy via [GitLab's CI pipeline](https://docs.gitlab.com/ee/ci/pipelines.html) please specify the following [CI variables](https://docs.gitlab.com/ee/ci/variables/README.html#creating-a-custom-environment-variable): + +* `S3_BUCKET_NAME` - name of the S3 bucket +* `AWS_ACCESS_KEY_ID` - the AWS access key id +* `AWS_SECRET_ACCESS_KEY` - the AWS secret +* `AWS_DEFAULT_REGION` - the AWS region. Optional, defaults to `us-west-1` + +#### Continuous integration + +Specifying CI variables via **Settings > CI/CD > Variables** allows a [continuous integration and delivery](https://docs.gitlab.com/ee/ci/introduction/#introduction-to-cicd-with-gitlab). + +#### Manual execution + +A deployment can also be triggered manually via **CI/CD > Pipelines > `Run Pipeline`.