Skip to content

Instantly share code, notes, and snippets.

@iMerica iMerica/.gitlab-ci.yml
Last active Jul 18, 2018

Embed
What would you like to do?
Automated Deployments of Create React Apps to Cloudfront using Scotty JS.
image: docker:latest
services:
- docker:dind
stages:
- build
- push
- deploy
variables:
REACT_TAG_NAME: registry.gitlab.com/<user>/<project>/<container-name>:$CI_COMMIT_REF_NAME
S3_BUCKET: xxxx
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
build:react:
artifacts:
paths:
- docker-images
stage: build
script:
- mkdir docker-images
- docker build --pull -t $REACT_TAG_NAME -f path/to/your/Dockerfile .
- docker save $REACT_TAG_NAME > docker-images/react.tar
push:react:
stage: push
script:
- docker load -i docker-images/react.tar
- docker push $REACT_TAG_NAME
only:
- master
deploy:react:
stage: deploy
script:
- docker run \
--rm \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
$REACT_TAG_NAME \
--source /tmp/build/ \
--region us-east-1 \
--bucket $S3_BUCKET \
--urlonly \
--spa
FROM node:8.11.3-slim as node_builder
MAINTAINER @iMichael
WORKDIR /app
COPY /src /app/src
RUN cd /app/src && \
npm install && \
npm run build
FROM node:8.11.3-slim as deployer
RUN groupadd -r react && useradd -r -g react react
RUN npm install scottyjs --global
COPY --from=node_builder /app/src/build /tmp/build
USER react
ENTRYPOINT ["scotty"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.