-
Notifications
You must be signed in to change notification settings - Fork 4
/
.gitlab-ci.yml
61 lines (55 loc) · 2.52 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
image: docker:latest
stages:
- build
- release
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
before_script:
- if [ "$CI_COMMIT_REF_NAME" != "master" ] && [ -z "$CI_COMMIT_TAG" ]; then BRANCH="/$CI_COMMIT_REF_NAME"; fi
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
build:
stage: build
tags:
- docker
script:
- docker build -t "$CI_REGISTRY_IMAGE$BRANCH:latest" .
- docker push "$CI_REGISTRY_IMAGE$BRANCH:latest"
# Publish tag
- >
if [ ! -z "$CI_COMMIT_TAG" ]; then
docker tag "$CI_REGISTRY_IMAGE$BRANCH:latest" "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG";
docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"; fi
# Publish to dockerhub
- >
if [ -z "$BRANCH" ] && [ ! -z "$DOCKERHUB_PASSWORD" ]; then
docker login -u "$DOCKERHUB_LOGIN" -p "$DOCKERHUB_PASSWORD";
docker tag "$CI_REGISTRY_IMAGE$BRANCH:latest" thann/pingg;
docker push thann/pingg; fi
release:
stage: release
only: [tags]
tags:
- docker
script:
- docker pull "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
- docker run --name=release --entrypoint sh "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" -c "npm install pkg; /app/node_modules/.bin/pkg . -t node10-macos,node10-win,node10-linux"
- mkdir public
# Build release binaries
- docker cp release:/app/pingg-macos "public/pingg-${CI_COMMIT_TAG}-macos"
- docker cp release:/app/pingg-linux "public/pingg-${CI_COMMIT_TAG}-linux"
- docker cp release:/app/pingg-win.exe "public/pingg-${CI_COMMIT_TAG}-win.exe"
- apk add --no-cache curl
# Publish release
- |
curl --fail --output "/dev/null" --silent --show-error --write-out "HTTP response: ${http_code}\n\n" \
--data "{\"tag_name\": \"${CI_COMMIT_TAG}\", \"name\": \"${CI_PROJECT_NAME} - ${CI_COMMIT_TAG}\", \"description\": \"${CI_COMMIT_TAG_MESSAGE:-Automated release}\", \"assets\": { \"links\": [{ \"name\": \"MacOS download\", \"url\": \"${CI_JOB_URL}/artifacts/raw/public/pingg-${CI_COMMIT_TAG}-macos?inline=false\" },{ \"name\": \"Windows download\", \"url\": \"${CI_JOB_URL}/artifacts/raw/public/pingg-${CI_COMMIT_TAG}-win.exe?inline=false\" },{ \"name\": \"Linux download\", \"url\": \"${CI_JOB_URL}/artifacts/raw/public/pingg-${CI_COMMIT_TAG}-linux?inline=false\" }] } }" \
--header "Content-Type: application/json" \
--header "Private-Token: ${RELEASE_KEY}" \
--request POST \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/releases"
artifacts:
paths:
- public
expire_in: 99 yrs