Build default Docker image on release

Signed-off-by: Tim Hansen <timbonicus@gmail.com>
This commit is contained in:
Tim Hansen
2022-05-27 11:28:57 -06:00
committed by Tim Hansen
parent f9e2ec2551
commit f281ad17c0
6 changed files with 117 additions and 29 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/create-app': patch
---
Adds the ability to define the Backstage app name using a `BACKSTAGE_APP_NAME`
environment variable when running `create-app`.
+89
View File
@@ -0,0 +1,89 @@
name: Build and push Docker Hub image
on:
repository_dispatch:
types: [release-published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
path: backstage
ref: v${{ github.event.client_payload.version }}
- name: setup-node
uses: actions/setup-node@v1
with:
node-version: 16.x
registry-url: https://registry.npmjs.org/
# Beginning of yarn setup, keep in sync between all workflows.
# TODO(Rugvip): move this to composite action once all features we use are supported
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/ # Needed for auth
# Cache every node_modules folder inside the monorepo
- name: cache all node_modules
id: cache-modules
uses: actions/cache@v2
with:
path: '**/node_modules'
# We use both yarn.lock and package.json as cache keys to ensure that
# changes to local monorepo packages bust the cache.
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
# If we get a cache hit for node_modules, there's no need to bring in the global
# yarn cache or run yarn install, as all dependencies will be installed already.
- name: find location of global yarn cache
id: yarn-cache
if: steps.cache-modules.outputs.cache-hit != 'true'
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: cache global yarn cache
uses: actions/cache@v2
if: steps.cache-modules.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
if: steps.cache-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
# End of yarn setup
- name: create-app
run: yarn backstage-create-app
working-directory: ./packages/create-app
env:
BACKSTAGE_APP_NAME: example-app
- name: yarn build
run: yarn build
working-directory: ./packages/create-app/example-app
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
uses: docker/build-push-action@v2
with:
context: './packages/create-app/example-app'
file: ./packages/create-app/example-app/packages/backend/Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/backstage:${{ github.event.client_payload.version }}
cache-from: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/backstage:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/backstage:buildcache,mode=max
+8 -1
View File
@@ -209,7 +209,7 @@ jobs:
# Grabs the version in the root package.json and creates a tag on GitHub
- name: Create a release tag
id: create_tag
run: node scripts/create-release-tag.js --dispatch-workflows
run: node scripts/create-release-tag.js
env:
GITHUB_TOKEN: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
@@ -219,6 +219,13 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
- name: Dispatch repository event
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
event-type: release-published
client-payload: '{"version": "${{ steps.create_tag.outputs.version }}"}'
# Notify everyone about this great new release :D
- name: Discord notification
uses: Ilshidur/action-discord@0.3.2
+5 -8
View File
@@ -1,10 +1,7 @@
name: Sync Release Manifest
on:
workflow_dispatch:
inputs:
version:
description: Version number, without any 'v' prefix
required: true
repository_dispatch:
types: [release-published]
jobs:
create-new-version:
@@ -23,7 +20,7 @@ jobs:
with:
path: backstage
# 'v' prefix is added here for the tag, we keep it out of the manifest logic
ref: v${{ github.event.inputs.version }}
ref: v${{ github.event.client_payload.version }}
# Checkout backstage/versions into /backstage/versions, which is where store the output
- name: Checkout versions
@@ -44,10 +41,10 @@ jobs:
cd backstage
mkdir -p scripts
wget -O scripts/assemble-manifest.js https://raw.githubusercontent.com/backstage/backstage/master/scripts/assemble-manifest.js
node scripts/assemble-manifest.js ${{ github.event.inputs.version }}
node scripts/assemble-manifest.js ${{ github.event.client_payload.version }}
cd versions
git add .
git commit -am "${{ github.event.inputs.version }}"
git commit -am "${{ github.event.client_payload.version }}"
git push
- name: Dispatch update-helper update
+8
View File
@@ -49,6 +49,14 @@ export default async (opts: OptionValues): Promise<void> => {
}
return true;
},
when: (a: Answers) => {
const envName = process.env.BACKSTAGE_APP_NAME;
if (envName) {
a.name = envName;
return false;
}
return true;
},
},
]);
+1 -20
View File
@@ -57,22 +57,7 @@ async function createGitTag(octokit, commitSha, tagName) {
}
}
async function dispatchReleaseWorkflows(octokit, releaseVersion) {
console.log('Dispatching release manifest sync');
await octokit.actions.createWorkflowDispatch({
owner: 'backstage',
repo: 'backstage',
workflow_id: 'sync_release-manifest.yml',
ref: 'master',
inputs: {
version: releaseVersion,
},
});
}
async function main() {
const shouldDispatch = process.argv.includes('--dispatch-workflows');
if (!process.env.GITHUB_SHA) {
throw new Error('GITHUB_SHA is not set');
}
@@ -90,11 +75,7 @@ async function main() {
await createGitTag(octokit, commitSha, tagName);
console.log(`::set-output name=tag_name::${tagName}`);
if (shouldDispatch) {
console.log(`Dispatching release workflows for ${tagName}`);
await dispatchReleaseWorkflows(octokit, releaseVersion);
}
console.log(`::set-output name=version::${releaseVersion}`);
}
main().catch(error => {