-
Notifications
You must be signed in to change notification settings - Fork 10
160 lines (135 loc) · 6.54 KB
/
docker-release.yml
File metadata and controls
160 lines (135 loc) · 6.54 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: On-Demand Release Docker Build
on:
release:
types: [published] # Automatic trigger on new releases
workflow_dispatch: # Manual trigger
inputs:
release_tag:
description: "Release tag to build (e.g., v2.7.0, v2.6.1)"
required: true
type: string
build_latest:
description: "Also tag as latest?"
required: false
default: false
type: boolean
permissions:
contents: read
packages: write # Needed to push images to GHCR
jobs:
build-and-push-release:
runs-on: ubuntu-latest
steps:
- name: Determine release info
id: release_info
run: |
if [ "${{ github.event_name }}" = "release" ]; then
# Automatic release trigger
RELEASE_TAG="${{ github.event.release.tag_name }}"
BUILD_LATEST="true"
echo "source=automatic_release" >> $GITHUB_OUTPUT
else
# Manual workflow dispatch
RELEASE_TAG="${{ github.event.inputs.release_tag }}"
BUILD_LATEST="${{ github.event.inputs.build_latest }}"
echo "source=manual_dispatch" >> $GITHUB_OUTPUT
fi
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
echo "build_latest=$BUILD_LATEST" >> $GITHUB_OUTPUT
echo "Building release: $RELEASE_TAG (source: manual/auto)"
- name: Checkout repository at release tag
uses: actions/checkout@v6
with:
ref: ${{ steps.release_info.outputs.release_tag }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Release Version and Define Image Tags
id: image_info
run: |
# Get release tag name from previous step
RELEASE_TAG="${{ steps.release_info.outputs.release_tag }}"
# Remove 'v' prefix if present (v2.7.0 -> 2.7.0)
VERSION=${RELEASE_TAG#v}
# Use GitHub owner and repo name for GHCR image path (lowercase)
OWNER_LOWER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
REPO_LOWER=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]')
IMAGE_NAME="ghcr.io/$OWNER_LOWER/$REPO_LOWER"
# Create timestamp for additional uniqueness
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
# Define tags
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "timestamp=$TIMESTAMP" >> $GITHUB_OUTPUT
echo "original_tag=nasa-ammos/common-workflow-service:$VERSION" >> $GITHUB_OUTPUT
echo "ghcr_tag_release=$IMAGE_NAME:$RELEASE_TAG" >> $GITHUB_OUTPUT
echo "ghcr_tag_version=$IMAGE_NAME:$VERSION" >> $GITHUB_OUTPUT
echo "ghcr_tag_latest=$IMAGE_NAME:latest" >> $GITHUB_OUTPUT
echo "ghcr_tag_temporal=$IMAGE_NAME:$VERSION-$TIMESTAMP" >> $GITHUB_OUTPUT
echo "build_latest=${{ steps.release_info.outputs.build_latest }}" >> $GITHUB_OUTPUT
echo "Building release: $RELEASE_TAG"
echo "Version: $VERSION"
echo "Build latest tag: ${{ steps.release_info.outputs.build_latest }}"
- name: Download Logstash
run: |
curl -o install/logging/logstash-8.12.0.zip https://artifacts.elastic.co/downloads/logstash/logstash-8.12.0-windows-x86_64.zip
- name: Build CWS Docker Image using script
run: |
cd ../install/docker/cws-image
chmod +x build.sh
# The script builds using the 'nasa-ammos/...' tag internally
./build.sh
if [ $? -ne 0 ]; then
echo "::error::Docker image build script failed."
exit 1
fi
- name: Tag image for GHCR release
run: |
echo "Tagging ${{ steps.image_info.outputs.original_tag }} with release tags..."
# Tag with original release tag (e.g., v2.7.0)
docker tag "${{ steps.image_info.outputs.original_tag }}" "${{ steps.image_info.outputs.ghcr_tag_release }}"
echo "✓ Tagged: ${{ steps.image_info.outputs.ghcr_tag_release }}"
# Tag with clean version (e.g., 2.7.0)
docker tag "${{ steps.image_info.outputs.original_tag }}" "${{ steps.image_info.outputs.ghcr_tag_version }}"
echo "✓ Tagged: ${{ steps.image_info.outputs.ghcr_tag_version }}"
# Temporal tag for uniqueness
docker tag "${{ steps.image_info.outputs.original_tag }}" "${{ steps.image_info.outputs.ghcr_tag_temporal }}"
echo "✓ Tagged: ${{ steps.image_info.outputs.ghcr_tag_temporal }}"
# Conditionally tag as latest
if [ "${{ steps.image_info.outputs.build_latest }}" = "true" ]; then
docker tag "${{ steps.image_info.outputs.original_tag }}" "${{ steps.image_info.outputs.ghcr_tag_latest }}"
echo "✓ Tagged: ${{ steps.image_info.outputs.ghcr_tag_latest }}"
else
echo "⏭ Skipping latest tag"
fi
- name: Push Docker images to GHCR
run: |
echo "Pushing release images to GHCR..."
docker push "${{ steps.image_info.outputs.ghcr_tag_release }}"
echo "✓ Pushed: ${{ steps.image_info.outputs.ghcr_tag_release }}"
docker push "${{ steps.image_info.outputs.ghcr_tag_version }}"
echo "✓ Pushed: ${{ steps.image_info.outputs.ghcr_tag_version }}"
docker push "${{ steps.image_info.outputs.ghcr_tag_temporal }}"
echo "✓ Pushed: ${{ steps.image_info.outputs.ghcr_tag_temporal }}"
# Conditionally push latest
if [ "${{ steps.image_info.outputs.build_latest }}" = "true" ]; then
docker push "${{ steps.image_info.outputs.ghcr_tag_latest }}"
echo "✓ Pushed: ${{ steps.image_info.outputs.ghcr_tag_latest }}"
fi
- name: Summary
run: |
echo "🎉 Release build complete!"
echo "Source: ${{ steps.release_info.outputs.source }}"
echo "Release: ${{ steps.image_info.outputs.release_tag }}"
echo "Images pushed:"
echo " - ${{ steps.image_info.outputs.ghcr_tag_release }}"
echo " - ${{ steps.image_info.outputs.ghcr_tag_version }}"
echo " - ${{ steps.image_info.outputs.ghcr_tag_temporal }}"
if [ "${{ steps.image_info.outputs.build_latest }}" = "true" ]; then
echo " - ${{ steps.image_info.outputs.ghcr_tag_latest }}"
fi