-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (83 loc) · 2.73 KB
/
build-deploy.yml
File metadata and controls
100 lines (83 loc) · 2.73 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
# This is a workflow to build a Docker image and deploy it to Docker Hub
name: Docker CI/CD
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: ["main"]
pull_request:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
PROJECT_NAME: utilplex
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_REPOSITORY: ${{ vars.DOCKER_HUB_REPOSITORY || 'utilplex' }}
IMAGE_TAG: ${{ github.sha }}
jobs:
build:
name: Build and test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Node 20.x
uses: actions/setup-node@v3
with:
node-version: "20.x"
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build:ci
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and export Docker image
uses: docker/build-push-action@v4
with:
context: .
load: true
tags: ${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Test Docker image
run: |
docker run --rm ${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }} echo "Docker image built successfully"
- name: Archive build
if: success()
uses: actions/upload-artifact@v4
with:
name: docker_meta
path: |
.docker/
Dockerfile
docker-compose.yml
if-no-files-found: ignore
deploy:
name: Deploy to Docker Hub
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: docker_meta
path: .
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ env.IMAGE_TAG }}
${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPOSITORY }}:latest