Skip to content

Commit d15029c

Browse files
ci: Added GitHub Actions to test starter install, and Gitlab CI example file for build and docker deploy
1 parent a329714 commit d15029c

File tree

3 files changed

+199
-0
lines changed

3 files changed

+199
-0
lines changed

.github/workflows/test-install.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test install
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags: ['**']
8+
pull_request:
9+
types:
10+
- opened
11+
- reopened
12+
- synchronize
13+
- ready_for_review
14+
15+
jobs:
16+
test-install:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Install Node.js
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: 20
24+
- uses: pnpm/action-setup@v3
25+
name: Install pnpm
26+
with:
27+
version: 8
28+
run_install: false
29+
- name: Install dependencies
30+
run: pnpm install

.gitlab-ci.yml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
image: node:20
2+
3+
stages:
4+
- build
5+
- docker
6+
- release
7+
8+
# AutoDevOps templates for security
9+
include:
10+
- template: Jobs/Secret-Detection.gitlab-ci.yml
11+
- template: Jobs/Dependency-Scanning.gitlab-ci.yml
12+
13+
.frontend-cache: &frontend-cache
14+
# See https://pnpm.io/continuous-integration#gitlab-ci
15+
cache:
16+
key:
17+
files:
18+
- pnpm-lock.yaml
19+
paths:
20+
- .pnpm-store
21+
22+
.staging-env: &staging-env
23+
environment:
24+
name: staging
25+
url: "https://my-website.test"
26+
variables:
27+
NUXT_PUBLIC_API_URL: "https://my-website.test"
28+
NUXT_PUBLIC_SITE_URL: "https://my-website.test"
29+
NUXT_PUBLIC_INTERVENTION_REQUEST_BASE_URL: "https://my-website.test/assets"
30+
NUXT_PUBLIC_INTERVENTION_REQUEST_NO_PROCESS_BASE_URL: "https://my-website.test/files"
31+
NUXT_APP_CHANNEL: "$CI_COMMIT_SHORT_SHA $CI_ENVIRONMENT_NAME"
32+
33+
.production-env: &production-env
34+
environment:
35+
name: production
36+
url: "https://www.my-website.test"
37+
variables:
38+
NUXT_PUBLIC_API_URL: "https://www.my-website.test"
39+
NUXT_PUBLIC_SITE_URL: "https://www.my-website.test"
40+
NUXT_PUBLIC_INTERVENTION_REQUEST_BASE_URL: "https://www.my-website.test/assets"
41+
NUXT_PUBLIC_INTERVENTION_REQUEST_NO_PROCESS_BASE_URL: "https://www.my-website.test/files"
42+
NUXT_APP_CHANNEL: "$CI_COMMIT_SHORT_SHA $CI_ENVIRONMENT_NAME"
43+
44+
45+
## Common scripts and artifacts for develop and main jobs
46+
.build-commons: &build-commons
47+
artifacts:
48+
name: "build_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHORT_SHA}"
49+
expire_in: 1 hour
50+
paths:
51+
- .output/
52+
# See https://pnpm.io/continuous-integration#gitlab-ci
53+
before_script:
54+
- corepack enable
55+
- corepack prepare pnpm@latest-8 --activate
56+
- pnpm config set store-dir .pnpm-store
57+
script:
58+
- cd frontend
59+
- pnpm install --config.platform=linuxmusl --config.architecture=x64
60+
# - pnpm lint
61+
- pnpm build
62+
63+
# ===========
64+
# SSR STAGING
65+
# ===========
66+
ssr_build_develop:
67+
stage: build
68+
interruptible: true
69+
only:
70+
- merge_requests
71+
- develop
72+
except:
73+
- tags
74+
- main
75+
<<: *frontend-cache
76+
<<: *staging-env
77+
<<: *build-commons
78+
79+
ssr_docker_develop:
80+
stage: docker
81+
only:
82+
- develop
83+
image: docker:git
84+
services:
85+
- docker:dind
86+
when: on_success
87+
<<: *staging-env
88+
needs: [ "ssr_build_develop" ]
89+
dependencies: [ "ssr_build_develop" ]
90+
script:
91+
- "docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}"
92+
# App image build
93+
- "docker build -t ${CI_REGISTRY_IMAGE}/node:develop -f docker/node/Dockerfile ."
94+
- "docker push ${CI_REGISTRY_IMAGE}/node:develop"
95+
96+
# ========
97+
# SSR PROD
98+
# ========
99+
ssr_build_tags:
100+
stage: build
101+
interruptible: true
102+
only:
103+
- tags
104+
<<: *frontend-cache
105+
<<: *production-env
106+
<<: *build-commons
107+
108+
ssr_docker_tags:
109+
stage: docker
110+
only:
111+
- tags
112+
image: docker:git
113+
<<: *production-env
114+
services:
115+
- docker:dind
116+
when: on_success
117+
needs: [ "ssr_build_tags" ]
118+
dependencies: [ "ssr_build_tags" ]
119+
script:
120+
# Connect to your Gitlab Registry
121+
- "docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}"
122+
# App image build
123+
- "docker build -t ${CI_REGISTRY_IMAGE}/node:latest -t ${CI_REGISTRY_IMAGE}/node:${CI_COMMIT_TAG} -f docker/node/Dockerfile ."
124+
- "docker push ${CI_REGISTRY_IMAGE}/node:latest"
125+
- "docker push ${CI_REGISTRY_IMAGE}/node:${CI_COMMIT_TAG}"
126+
127+
128+
# ==========================================
129+
# Create release on Gitlab repository
130+
# ==========================================
131+
create_gitlab_release:
132+
stage: release
133+
image: registry.gitlab.com/gitlab-org/release-cli:latest
134+
rules:
135+
- if: $CI_COMMIT_TAG
136+
script:
137+
- echo "Running the release job."
138+
needs: [ "common_docker_images" ]
139+
<<: *production-env
140+
when: on_success
141+
release:
142+
tag_name: $CI_COMMIT_TAG
143+
name: 'Release $CI_COMMIT_TAG'
144+
description: './CHANGELOG.md'

docker/node/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM node:20-alpine
2+
3+
# Add libvips for IPX support nuxt/image on Alpine
4+
RUN apk add --upgrade --no-cache vips-dev build-base --repository https://alpine.global.ssl.fastly.net/alpine/v3.10/community/
5+
6+
# create destination directory
7+
RUN mkdir -p /usr/src/nuxt-app && \
8+
apk add curl
9+
WORKDIR /usr/src/nuxt-app
10+
11+
HEALTHCHECK --start-period=1m30s --interval=1m --timeout=6s CMD curl --fail -I http://localhost:3000
12+
13+
# copy the app, note .dockerignore
14+
COPY .output /usr/src/nuxt-app/.output
15+
# set app serving to permissive / assigned
16+
ENV HOST=0.0.0.0
17+
# set app port
18+
ENV PORT=3000
19+
ENV NODE_ENV=production
20+
ENV NITRO_PRESET=node_cluster
21+
# expose 5000 on container
22+
EXPOSE 3000
23+
# start the app
24+
CMD [ "node", ".output/server/index.mjs" ]
25+

0 commit comments

Comments
 (0)