-
Notifications
You must be signed in to change notification settings - Fork 6
97 lines (83 loc) · 3.15 KB
/
build-docker.yml
File metadata and controls
97 lines (83 loc) · 3.15 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
name: 'Build Docker Image'
# Only run this when on the master branch and changes are made to the Dockerfile, src, package.json, package-lock.json, tsconfig.json, or .github/workflows/build-docker.yml
on:
push:
branches:
- master
paths:
- 'Dockerfile'
- 'src/**'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '.github/workflows/build-docker.yml'
# Allows you to run this workflow manually from the Actions tab. We can override the branch, image name, and docker registry.
workflow_dispatch:
inputs:
branch:
description: 'Branch'
required: true
default: 'master'
image:
description: 'Image Name'
required: true
default: 'mfdlabs/rbx-proxy'
registry:
description: 'Docker Registry'
required: true
default: 'docker.io'
jobs:
build:
if: "!contains(github.event.head_commit.message, '[SKIP IMAGE]')"
runs-on: ubuntu-latest
# If DOCKER_REGISTRY is not set, default to docker.io
env:
DOCKER_REGISTRY: ${{ github.event.inputs.registry || secrets.DOCKER_REGISTRY || 'docker.io' }}
IMAGE_NAME: ${{ github.event.inputs.image || secrets.IMAGE_NAME || 'mfdlabs/rbx-proxy' }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
# Pushes 2 identical images to the registry, one with the tag latest and one with the version in package.json
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.branch || github.ref }}
- uses: actions/setup-node@v2
with:
node-version: '17.x'
# Error if IMAGE_NAME is not set
- name: Check IMAGE_NAME
run: |
if [ -z "$IMAGE_NAME" ]; then
echo "IMAGE_NAME is not set"
exit 1
fi
# Error if DOCKER_USERNAME is not set
- name: Check DOCKER_USERNAME
run: |
if [ -z "$DOCKER_USERNAME" ]; then
echo "DOCKER_USERNAME is not set"
exit 1
fi
# Error if DOCKER_PASSWORD is not set
- name: Check DOCKER_PASSWORD
run: |
if [ -z "$DOCKER_PASSWORD" ]; then
echo "DOCKER_PASSWORD is not set"
exit 1
fi
# Run updateVersion.js to update the version in package.json
- name: Update version
run: node updateVersion.js
# Step to get the version from package.json
- name: Get version
id: get_version
run: echo ::set-output name=version::$(node -p "require('./package.json').version")
# Build the image
- name: Build image
run: docker build -t ${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.version }} -t ${{ env.IMAGE_NAME }}:latest .
# Login to the registry
- name: Login to registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login ${{ env.DOCKER_REGISTRY }} -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
# Push the image to the registry
- name: Push image
run: docker push ${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.version }} && docker push ${{ env.IMAGE_NAME }}:latest