Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo #339

Open
wants to merge 16 commits into
base: dependabot/maven/repo-management-github-actions-example/maths/junit-junit-4.13.1
Choose a base branch
from
Open

repo #339

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions .github/workflows/deploy-to-ionos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Please do not edit this file.
# More information under https://docs.ionos.space/docs/github-actions-customization/
# version: 2022-07-21

name: "Deploy Now: Deploy to IONOS"

on:
workflow_dispatch:
inputs:
version:
required: true
type: string
project-id:
required: true
type: string
branch-id:
required: true
type: string
deployment-ids:
require: true
type: string

concurrency: ${{ github.ref }}

jobs:
deploy-to-ionos:
runs-on: ubuntu-latest
permissions:
actions: read
strategy:
matrix:
deployment-id: ${{ fromJson(inputs.deployment-ids) }}
steps:
- name: Update deployment status
uses: ionos-deploy-now/project-action@v1
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-us.ionos.space
project-id: ${{ inputs.project-id }}
branch-id: ${{ inputs.branch-id }}
deployment-id: ${{ matrix.deployment-id }}
action: update-status
status: in_progress

- name: Retrieve stored deployment
uses: ionos-deploy-now/artifact-action@v1
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-us.ionos.space
project-id: ${{ inputs.project-id }}
branch-id: ${{ inputs.branch-id }}
version: ${{ inputs.version }}
action: download

- name: Fetch deployment info
uses: ionos-deploy-now/project-action@v1
id: deployment
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-us.ionos.space
project-id: ${{ inputs.project-id }}
branch-id: ${{ inputs.branch-id }}
deployment-id: ${{ matrix.deployment-id }}
action: retrieve-info

- name: Render templates
uses: ionos-deploy-now/template-renderer-action@v2
id: template
with:
deployment-id: ${{ matrix.deployment-id }}
data: "[${{ steps.deployment.outputs.template-variables }}, ${{ toJson(secrets) }}]"
input-directory: deployment
output-directory: deployment
intermediate-data-file: deployment/.template-renderer-data

- name: Render real site-url to all files
run: |
for file in `grep -rl 'https://IONOS_DEPLOY_NOW_SITE_URL' .`; do
sed -i $file -e 's|https://IONOS_DEPLOY_NOW_SITE_URL|${{ fromJson(steps.deployment.outputs.info).site-url }}|g'
done

- name: Render SSH user secret name
run: echo SSH_USERNAME_SECRET=IONOS_DEPLOYMENT_`echo ${{ matrix.deployment-id }} | tr '[:lower:]' '[:upper:]' | tr '-' '_'`_SSH_USERNAME >> $GITHUB_ENV

- name: Deploy to IONOS
uses: ionos-deploy-now/deploy-to-ionos-action@v2
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-us.ionos.space
project-id: ${{ inputs.project-id }}
branch-id: ${{ inputs.branch-id }}
deployment-id: ${{ matrix.deployment-id }}
deployment-info: ${{ steps.deployment.outputs.info }}
ssh-user: ${{ secrets[env.SSH_USERNAME_SECRET] }}
ssh-key: ${{ secrets.IONOS_SSH_KEY }}

- name: Update deployment status
if: ${{ always() }}
uses: ionos-deploy-now/project-action@v1
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-us.ionos.space
project-id: ${{ inputs.project-id }}
branch-id: ${{ inputs.branch-id }}
deployment-id: ${{ matrix.deployment-id }}
action: update-status
status: ${{ job.status }}

notify-deployment-finished:
needs: deploy-to-ionos
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Notify all deployments finished
uses: ionos-deploy-now/project-action@v1
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-us.ionos.space
project-id: ${{ inputs.project-id }}
branch-id: ${{ inputs.branch-id }}
action: set-deployments-finished
41 changes: 41 additions & 0 deletions .github/workflows/project-examples-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# To better understand this file read this:
# https://docs.ionos.space/docs/github-actions-customization/

name: "Deploy Now: Execute Build"

on:
workflow_call:
inputs:
site-url:
required: true
type: string
branch-id:
required: true
type: string

env:
DEPLOYMENT_FOLDER: ./

jobs:
# Please do not rename this job
build-project:
name: build project-examples
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'

# Please do not touch the following action
- name: Store deployment content
uses: ionos-deploy-now/artifact-action@v1
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-us.ionos.space
project-id: 74c1a5b2-dc4d-4da7-8f37-3454d87ef20d
branch-id: ${{ inputs.branch-id }}
version: ${{ github.sha }}
folder: ${{ env.DEPLOYMENT_FOLDER }}
config-file: .deploy-now/project-examples/config.yaml
action: upload
55 changes: 55 additions & 0 deletions .github/workflows/project-examples-orchestration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Please do not edit this file.
# Build steps can be customized in the project-examples-build.yaml.
# More information under https://docs.ionos.space/docs/github-actions-customization/
# version: 2022-07-21

name: "Deploy Now: Orchestration"
run-name: "Deploy Now: Build project-examples · ${{ github.event.head_commit.message || format('Triggered by {0}', github.triggering_actor) }}"

on:
- push
- workflow_dispatch

jobs:
retrieve-project:
name: check readiness
runs-on: ubuntu-latest
outputs:
deployment-enabled: ${{ fromJson(steps.project.outputs.info).deployment-enabled }}
branch-id: ${{ fromJson(steps.project.outputs.info).branch-id }}
steps:
- name: Fetch project data
uses: ionos-deploy-now/project-action@v1
id: project
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-us.ionos.space
project-id: 74c1a5b2-dc4d-4da7-8f37-3454d87ef20d
action: retrieve-info


build:
name: build
needs: retrieve-project
if: ${{ needs.retrieve-project.outputs.deployment-enabled == 'true' }}
uses: ./.github/workflows/project-examples-build.yaml
with:
site-url: https://IONOS_DEPLOY_NOW_SITE_URL
branch-id: ${{ needs.retrieve-project.outputs.branch-id }}
secrets: inherit

deploy:
name: trigger deployment
needs:
- retrieve-project
- build
runs-on: ubuntu-latest
steps:
- name: Dispatch deployment(s)
uses: ionos-deploy-now/project-action@v1
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-us.ionos.space
project-id: 74c1a5b2-dc4d-4da7-8f37-3454d87ef20d
branch-id: ${{ needs.retrieve-project.outputs.branch-id }}
action: dispatch-deployments
3 changes: 2 additions & 1 deletion docker-oci-examples/fat-manifest-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ For this demo, we will be using [buildx](https://github.com/docker/buildx) in or
Build and push multi platforms image:
> docker login DOCKER_REG_URL
> docker buildx install
> docker build --platform=linux/amd64,linux/arm64,linux/arm/v7 --tag=DOCKER_REG_URL/TARGET_REPO/multiarch-image:1 -f=Dockerfile.Fatmanifest --metadata-file=build-metadata --push .
> docker buildx create --use --name mybuilder --driver docker-container
> docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 --tag=DOCKER_REG_URL/TARGET_REPO/multiarch-image:1 -f=Dockerfile.Fatmanifest --metadata-file=build-metadata --push .

Configure Artifactory:
> jf c add MY_SERVER_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ This is an example showing how to add a BuildConfig in OpenShift and use it to b
```
* Configure JFrog CLI:
```
jfrog config add
jf config add
```
* Use JFrog CLI to start a new build from the BuildConfig we just created and collect build info. Replace the placeholders and run:
```
jfrog rt oc start-build jfrog-oc-build-example --server-id=<JFrog CLI config server ID> --repo=<Docker repository name> --build-name=oc-build-example --build-number=1
jf rt oc start-build jfrog-oc-build-example --server-id=<JFrog CLI config server ID> --repo=<Docker repository name> --build-name=oc-build-example --build-number=1
```
* Publish build info to Artifactory. Replace the placeholder and run:
```
jfrog rt build-publish oc-build-example 1 --server-id=<JFrog CLI config server ID>
jf rt build-publish oc-build-example 1 --server-id=<JFrog CLI config server ID>
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spec:
type: Git
git:
uri: 'https://github.com/jfrog/project-examples'
contextDir: /openshift-examples/openshift-build-example
contextDir: /docker-oci-examples/openshift-examples/openshift-build-example
strategy:
type: Docker
output:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ jobs:
name: calculate-ci-job
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Setup JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Setup JFrog CLI
uses: jfrog/setup-jfrog-cli@v1
uses: jfrog/setup-jfrog-cli@v2
env:
JF_ARTIFACTORY_1: ${{ secrets.JF_ARTIFACTORY_SECRET_1 }}
JF_ENV_1: ${{ secrets.JF_SECRET_ENV_1 }}
M2_HOME: /usr/local/apache-maven/apache-maven-3.6.3

- name: Ping JFrog CLI
run: jfrog rt ping
run: jf rt ping

- name: Set Environment Variables
run: |
Expand All @@ -44,61 +44,61 @@ jobs:
# if pushed from a feature branch, should create a proper repository in artifactory for that
- name: Feature Branch Repository Creation
run: |
jfrog rt rc templates/local-repo-template.json --vars key1=$repository
jfrog rt rc templates/remote-repo-template.json --vars key1=$repository
jfrog rt rc templates/virtual-repo-template.json --vars key1=$repository
jf rt rc templates/local-repo-template.json --vars key1=$repository
jf rt rc templates/remote-repo-template.json --vars key1=$repository
jf rt rc templates/virtual-repo-template.json --vars key1=$repository

- if: always()
name: Feature Branch Repository Update
env:
SERVER_ID: tal-eplus-saas
run: |
echo "::set-env name=repository::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')"
jfrog rt mvnc --server-id-resolve=$SERVER_ID --server-id-deploy=$SERVER_ID --repo-resolve-releases=auto-cli-virtual-$repository --repo-resolve-snapshots=auto-cli-virtual-$repository --repo-deploy-releases=auto-cli-virtual-$repository --repo-deploy-snapshots=auto-cli-virtual-$repository
jf mvnc --server-id-resolve=$SERVER_ID --server-id-deploy=$SERVER_ID --repo-resolve-releases=auto-cli-virtual-$repository --repo-resolve-snapshots=auto-cli-virtual-$repository --repo-deploy-releases=auto-cli-virtual-$repository --repo-deploy-snapshots=auto-cli-virtual-$repository

- if: always()
name: Build & Deploy
run: |
cd maths && jfrog rt mvn clean install
cd maths && jf mvn clean install

- if: always()
name: Publish Build Information
run: |
# Collect environment variables for the build
jfrog rt bce
jf rt bce
# Collect VCS details from git and add them to the build
jfrog rt bag
jf rt bag
# Publish build info
jfrog rt bp
jf rt bp

- if: always()
name: Xray Scan
run: |
jfrog rt bs
jf bs

- if: always()
name: Feature Branch Repository Deletion
env:
NUMBER_OF_DAYS_TO_KEEP: 90
run: |
# Extract all the LOCAL repositories created automatically by the CI process
jfrog rt curl -XGET /api/repositories | jq '[.[] | .key | select(test("auto-cli-local"))]' > deletion/auto_created_repositories.json && cat deletion/auto_created_repositories.json
jf rt curl -XGET /api/repositories | jq '[.[] | .key | select(test("auto-cli-local"))]' > deletion/auto_created_repositories.json && cat deletion/auto_created_repositories.json

# Calculate for which month are we going back to verify who should be deleted
jq -n 'now - 3600 * 24 * '$NUMBER_OF_DAYS_TO_KEEP' | gmtime | todate' > deletion/months_indicator && cat deletion/months_indicator

# Iterate over all the repositories, delete those by the latest file that was modified
jq -c '.[]' deletion/auto_created_repositories.json | while read i; do
echo Iterating repository = $i
sh -c "jfrog rt s --spec deletion/repositories-spec.json --spec-vars='key1="$i"' > deletion/search_results && cat deletion/search_results"
sh -c "jf rt s --spec deletion/repositories-spec.json --spec-vars='key1="$i"' > deletion/search_results && cat deletion/search_results"

# If the repository is empty / latest modified file is older > NUMBER_OF_DAYS_TO_KEEP days => DELETE the repository
if [[ $(cat deletion/search_results) == "[]" ]]; then
echo "Deleting repository: $i, repository is empty"
sh -c "jfrog rt rdel $i --quiet && jfrog rt rdel ${i//local/virtual} --quiet && jfrog rt rdel ${i//local/jcenter} --quiet"
sh -c "jf rt rdel $i --quiet && jf rt rdel ${i//local/virtual} --quiet && jf rt rdel ${i//local/jcenter} --quiet"
elif [[ $(cat deletion/search_results | jq --arg month_indicator $(cat deletion/months_indicator) '.[] | .modified | . <= $month_indicator') = "true" ]]; then
echo "Deleting repository: $i, too old to keep in Artifactory"
sh -c "jfrog rt rdel $i --quiet && jfrog rt rdel ${i//local/virtual} --quiet && jfrog rt rdel ${i//local/jcenter} --quiet"
sh -c "jf rt rdel $i --quiet && jf rt rdel ${i//local/virtual} --quiet && jf rt rdel ${i//local/jcenter} --quiet"
else
echo "Skipping Repository deletion - repository is still relevant"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ This is an example Github workflow, which uses the [Setup JFrog CLI Github Actio
3. Configure the details of your Artifactory server by running ```jfrog c add```.
4. Using the server ID you configured, export the server details by running ```jfrog c export <Server ID>```.
5. Copy the generated token to the clipboard.
6. In the Github repository you created, create a [secret](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) named JF_ARTIFACTORY_SERVER_1. Set the value of the secret to be the generated token you copied to the clipboard.
6. In the Github repository you created, create a [secret](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) named JF_SECRET_ENV_1. Set the value of the secret to be the generated token you copied to the clipboard.
7. Push the [workflow.yml](workflow.yml) file as part of this example, under `.github/workflows/` in your Github repository.
8. Watch the workflow running following any push to the repository.
12 changes: 6 additions & 6 deletions github-action-examples/simple-github-action-example/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Setup JFrog CLI
uses: jfrog/setup-jfrog-cli@v1
uses: jfrog/setup-jfrog-cli@v2
env:
JF_ARTIFACTORY_SERVER: ${{ secrets.JF_ARTIFACTORY_SERVER_1 }}
JF_ENV_1: ${{ secrets.JF_SECRET_ENV_1 }}
- name: Run JFrog CLI
run: |
# Collect environment variables for the build
jfrog rt bce
jf rt bce
# Collect VCS details from git and add them to the build
jfrog rt bag
jf rt bag
# Publish build info
jfrog rt bp
jf rt bp
Loading