-
Notifications
You must be signed in to change notification settings - Fork 2
75 lines (69 loc) · 2.38 KB
/
dockerbuild.yaml
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
name: Build & push images for 'Vaccine solution - order manager'
on:
push:
branches:
- master
paths-ignore:
- 'docs/**'
jobs:
validate-docker-secrets:
runs-on: ubuntu-latest
steps:
- name: Validate docker registry secrets are defined
id: validate-docker-secrets
run: |
echo "Validating docker registry secrets are defined on the repository"
FAIL=false
validate_secret(){
FIELD=$1
VALUE=$2
if [ -z "${VALUE}" ]; then
echo "The secret ${FIELD} needs to be set on this repository."
FAIL=true
else
echo "The secret ${FIELD} is set on this repository."
fi
}
validate_secret DOCKER_USERNAME ${DOCKER_USERNAME}
validate_secret DOCKER_PASSWORD ${DOCKER_PASSWORD}
validate_secret DOCKER_REPOSITORY ${DOCKER_REPOSITORY}
validate_secret DOCKER_IMAGE_NAME ${DOCKER_IMAGE_NAME}
validate_secret DOCKER_REGISTRY ${DOCKER_REGISTRY}
if [ "${FAIL}" = "true" ]; then
exit 1
fi
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_REPOSITORY: ${{ secrets.DOCKER_REPOSITORY }}
DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_IMAGE_NAME }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
build-docker-images:
needs:
validate-docker-secrets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build the app docker image
id: build-container-image
run: |
IMAGE_NAME="${DOCKER_REG}/${DOCKER_R}/${DOCKER_I}"
docker login -u ${DOCKER_U} -p ${DOCKER_P} ${DOCKER_REG}
echo "Build and push the docker image $IMAGE_NAME"
cd ${WORKDIR}
docker build -f ${DOCKERFILE} -t ${IMAGE_NAME}:${IMAGE_TAG} .
docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${IMAGE_NAME}:latest
docker push ${IMAGE_NAME}
env:
DOCKER_U: ${{ secrets.DOCKER_USERNAME }}
DOCKER_P: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_R: ${{ secrets.DOCKER_REPOSITORY }}
DOCKER_I: ${{ secrets.DOCKER_IMAGE_NAME }}
DOCKER_REG: ${{ secrets.DOCKER_REGISTRY }}
WORKDIR: .
DOCKERFILE: ./Dockerfile
IMAGE_TAG: 0.1.0