Skip to content

Commit f219403

Browse files
committed
build: add Github Action build and push
1 parent b7a292e commit f219403

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Build and Push Docker Images
2+
description: This workflow builds and pushes Docker images
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- master
9+
tags:
10+
- '*'
11+
pull_request:
12+
branches:
13+
- main
14+
- master
15+
16+
jobs:
17+
build-and-push:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '25.2.0'
28+
cache: 'npm'
29+
30+
- name: Install dependencies
31+
run: npm install
32+
33+
- name: Run tests
34+
run: npm run test
35+
36+
- name: Docker meta
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
# list of Docker images to use as base name for tags
41+
images: |
42+
arquivo/arquivo-webapp
43+
# generate Docker tags based on the following events/attributes
44+
tags: |
45+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }}
46+
type=schedule
47+
type=ref,event=branch
48+
type=ref,event=pr
49+
type=semver,pattern={{version}}
50+
type=semver,pattern={{major}}.{{minor}}
51+
type=semver,pattern={{major}}
52+
type=sha
53+
54+
- name: Set up Docker Buildx
55+
uses: docker/setup-buildx-action@v3
56+
57+
- name: Log in to Docker Hub
58+
if: github.event_name != 'pull_request'
59+
uses: docker/login-action@v3
60+
with:
61+
username: ${{ secrets.DOCKERHUB_USERNAME }}
62+
password: ${{ secrets.DOCKERHUB_TOKEN }}
63+
64+
- name: Build and push Docker image
65+
uses: docker/build-push-action@v6
66+
with:
67+
push: ${{ github.event_name != 'pull_request' }}
68+
tags: ${{ steps.meta.outputs.tags }}
69+
labels: ${{ steps.meta.outputs.labels }}
70+
target: production
71+
72+
- name: Logout from Docker Hub
73+
if: github.event_name != 'pull_request'
74+
run: docker logout

0 commit comments

Comments
 (0)