-
Notifications
You must be signed in to change notification settings - Fork 2
153 lines (142 loc) · 5.49 KB
/
docker-public.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: UISPTools_DockerPackage
on:
# push:
# Publish `master` as Docker `latest` image.
#branches:
# - '**'
# - master
# - '!master'
# Publish `v1.2.3` tags as releases.
#tags:
# - v*
# - v*
release:
types:
- created
# Run tests for any PRs.
env:
IMAGE_NAME: uisptools
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
echo Nothing to do here yet...
fi
# echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
# IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/sipsrv:latest
# docker pull $IMAGE_ID
# docker tag $IMAGE_ID sipsrv:latest
#docker build . --file Dockerfile
# See also https://docs.docker.com/docker-hub/builds/
build:
# Ensure test job passes before pushing image.
runs-on: ubuntu-latest
#if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Get package version
id: step_1
run: |
cat package.json
grep -m1 version package.json
APP_VERSION=$(jq -r .version package.json)
echo "app_version=$APP_VERSION" >> $GITHUB_ENV
echo Node Package Version $APP_VERSION
- name: set pakagename
run: |
PACKAGE_NAME=${{ env.IMAGE_NAME }}
echo "package_name=$PACKAGE_NAME" >> $GITHUB_ENV
echo Package Name $PACKAGE_NAME
#- name: update pakage name
# if: ${{ github.ref != 'refs/heads/main' && github.ref != "refs/tags/"* }}
# run: |
# echo Old Package Name $PACKAGE_NAME
# BRANCH_NAME=${GITHUB_REF#refs/heads/}
# # Force Lower Case
# [[ "${{ github.ref }}" == "refs/heads/"* ]] && BRANCH_NAME=$(echo $BRANCH_NAME | sed -e 's/\(.*\)/\L\1/')
# # remove spaces
# BRANCH_NAME=$(echo $BRANCH_NAME | sed -e 's/ /_/g')
# echo Branch Name $BRANCH_NAME
# PACKAGE_NAME=${{ env.IMAGE_NAME }}_$BRANCH_NAME
# echo "package_name=$PACKAGE_NAME" >> $GITHUB_ENV
# echo New Package Name $PACKAGE_NAME
- name: Build Docker Image
id: step_2
run: |
APP_VERSION=${{ env.app_version }}
PACKAGE_NAME=${{ env.package_name }}
echo App Version $APP_VERSION
echo Package Name $PACKAGE_NAME
docker build . --file Dockerfile --tag $PACKAGE_NAME
IMAGE_ID=ghcr.io/${{ github.repository }}/$PACKAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "master" ] && VERSION=latest
echo "version=$VERSION" >> $GITHUB_ENV
echo "image_id=$IMAGE_ID" >> $GITHUB_ENV
- name: Log in to the GitHub Container registry
id: step_3
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: 'ghcr.io'
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to GitHub
id: step_4
run: |
IMAGE_ID=${{ env.image_id }}
PACKAGE_NAME=${{ env.package_name }}
APP_VERSION=${{ env.app_version }}
VERSION=${{ env.version }}
echo ------------
echo PACKAGE_NAME: $PACKAGE_NAME
echo IMAGE_ID: $IMAGE_ID
echo APP_VERSION: $APP_VERSION
echo ------------
echo Try: "$IMAGE_ID:$APP_VERSION"
echo push step - Node Package Version $APP_VERSION
# VERSION=latest
docker tag $PACKAGE_NAME $IMAGE_ID:$APP_VERSION
docker push $IMAGE_ID:$APP_VERSION
docker tag $PACKAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:latest
- name: Log in to the Docker Container registry
id: step_5
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: 'docker.io'
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Push to Docker
id: step_6
run: |
IMAGE_ID=${{ env.image_id }}
PACKAGE_NAME=${{ env.package_name }}
APP_VERSION=${{ env.app_version }}
VERSION=${{ env.version }}
DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}
echo ------------
echo PACKAGE_NAME: $PACKAGE_NAME
echo IMAGE_ID: $IMAGE_ID
echo APP_VERSION: $APP_VERSION
echo ------------
echo Try: "$DOCKER_USERNAME/$PACKAGE_NAME:$APP_VERSION"
echo push step - Node Package Version $APP_VERSION
# VERSION=latest
docker tag $PACKAGE_NAME $DOCKER_USERNAME/$PACKAGE_NAME:$APP_VERSION
docker push $DOCKER_USERNAME/$PACKAGE_NAME:$APP_VERSION
docker tag $PACKAGE_NAME $DOCKER_USERNAME/$PACKAGE_NAME:latest
docker push $DOCKER_USERNAME/$PACKAGE_NAME:latest