-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (92 loc) · 3.67 KB
/
server.yml
File metadata and controls
114 lines (92 loc) · 3.67 KB
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
name: Server workflow
on:
push:
branches: [ main ]
paths:
- 'services/server/**'
- 'k8s/server.template'
- '.github/workflows/server.yml'
workflow_dispatch:
env:
SCOPE: services/server
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OKTETO_TOKEN: ${{ secrets.OKTETO_TOKEN }}
UNIT_TEST_IMAGE: trainscoding-unit-tests
SERVER_IMAGE: trainscoding-server
SERVER_PORT: 8080
jobs:
run-tests-and-generate-docker-unit-test-image:
name: Server workflow
runs-on: ubuntu-20.04
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Set up NodeJS 16
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Run eslint and prettier to lint and fix code style
run: make lint-fix
- name: Login to DockerHub
run: docker login -u $DOCKERHUB_USER -p $DOCKERHUB_TOKEN
- name: Build unit test image
run: |
docker build -t $DOCKERHUB_USER/$UNIT_TEST_IMAGE:latest -f docker/environment/test/Dockerfile-unit-tests .
docker tag $DOCKERHUB_USER/$UNIT_TEST_IMAGE $DOCKERHUB_USER/$UNIT_TEST_IMAGE:latest
docker image push --all-tags $DOCKERHUB_USER/$UNIT_TEST_IMAGE
- name: Test server service
run: SCOPE=services/server make test
build-and-push-service-image:
name: Build and push service's image
runs-on: ubuntu-20.04
needs: [run-tests-and-generate-docker-unit-test-image]
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Set up NodeJS 16
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Build Service Server artifact
run: BUILD_SCOPE=service SERVICE_NAME=server make build
- name: Build docker image for SERVER
run: |
TIMESTAMP=$(date +'%Y%m%d.%H%M%S')
IMAGE_VERSION=${{ github.sha }}.$TIMESTAMP
docker build -t $SERVER_IMAGE -f services/server/Dockerfile ./services/server
- name: Create image variables
run: |
TIMESTAMP=$(date +'%Y%m%d.%H%M%S')
IMAGE_TAG=${{ github.sha }}.$TIMESTAMP
DOCKER_IMAGE=$DOCKERHUB_USER/$SERVER_IMAGE:$IMAGE_TAG
echo $IMAGE_TAG | xargs -I{} echo '::set-output name=IMAGE_TAG::{}'
echo $DOCKER_IMAGE | xargs -I{} echo '::set-output name=DOCKER_IMAGE::{}'
id: image-vars
- name: Create server.yml file using template by replacing dynamic variables
run: |
sed \
-e s,%DOCKER_IMAGE%,${{ steps.image-vars.outputs.DOCKER_IMAGE }},g \
-e s,%SERVER_PORT%,$SERVER_PORT,g \
k8s/server.template > k8s/server.yml
- name: Login to DockerHub
run: docker login -u $DOCKERHUB_USER -p $DOCKERHUB_TOKEN
- name: Push newest Server image to DockerHub
run: |
docker tag $SERVER_IMAGE ${{ steps.image-vars.outputs.DOCKER_IMAGE }}
docker image push --all-tags $DOCKERHUB_USER/$SERVER_IMAGE
- name: Login to GitHub Docker Registry
run: echo $GITHUB_TOKEN | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image to GitHub Docker Registry
id: push-to-github-registry
run: |
GITHUB_REPOSITORY=$(echo ${{ github.repository }} | awk '{print tolower($0)}')
docker tag $SERVER_IMAGE ghcr.io/$GITHUB_REPOSITORY/$SERVER_IMAGE:${{ steps.image-vars.outputs.IMAGE_TAG }}
docker image push --all-tags ghcr.io/$GITHUB_REPOSITORY/$SERVER_IMAGE
- name: Depoly to okteto, using kubectl and Okteto cli
run: |
curl https://get.okteto.com -sSfL | sh
okteto login --token $OKTETO_TOKEN
okteto namespace
kubectl apply -f k8s/server.yml