-
Notifications
You must be signed in to change notification settings - Fork 1
97 lines (97 loc) · 3.74 KB
/
Copy pathdocker-webapp.yml
File metadata and controls
97 lines (97 loc) · 3.74 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: Docker WebApp
on:
workflow_run:
workflows: ["Angular WebApp Build"]
types: [completed]
branches: [main]
tags: ['v*.*.*', 'latest']
release:
types: [published]
workflow_dispatch:
inputs:
branch:
description: 'Branch or commit to build'
required: true
default: 'main'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-webapp
jobs:
deploy-web:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'release' || github.event_name == 'workflow_dispatch' }}
steps:
- uses: haya14busa/action-cond@v1
id: condval
with:
cond: ${{ github.event_name == 'workflow_dispatch' }}
if_true: "${{ github.event.inputs.branch }}"
if_false: " ${{ github.ref_name }}"
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ steps.condval.outputs.value }}
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# GitHub Action to install QEMU static binaries.
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v4.1.0
# GitHub Action to set up Docker Buildx.
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4.1.0
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
# Determine Dockerfile and cache scope based on branch/event
- name: Set build configuration
id: build-config
run: |
if [[ "${{ github.event_name }}" == "release" ]] || [[ "${{ steps.condval.outputs.value }}" == *"main"* ]]; then
echo "dockerfile=WebApp/Dockerfile.production" >> $GITHUB_OUTPUT
echo "cache-scope=prod" >> $GITHUB_OUTPUT
{
echo 'tags<<EOF'
echo '${{ steps.meta.outputs.tags }}'
echo 'EOF'
} >> $GITHUB_OUTPUT
else
echo "dockerfile=WebApp/Dockerfile" >> $GITHUB_OUTPUT
echo "cache-scope=dev" >> $GITHUB_OUTPUT
{
echo 'tags<<EOF'
echo '${{ steps.meta.outputs.tags }}'
echo 'EOF'
} >> $GITHUB_OUTPUT
fi
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v7.2.0
with:
context: WebApp/
file: ${{ steps.build-config.outputs.dockerfile }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.build-config.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
cache-from: type=gha, scope=${{ github.workflow }}-${{ steps.build-config.outputs.cache-scope }}
cache-to: type=gha, scope=${{ github.workflow }}-${{ steps.build-config.outputs.cache-scope }}