Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #250 from fabriziosestito/docker_cd
Browse files Browse the repository at this point in the history
Build containers in CI/CD
  • Loading branch information
stefanotorresi committed Sep 20, 2021
2 parents 962a7fb + 4f2591a commit ce1387e
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 90 deletions.
168 changes: 155 additions & 13 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ on:
pull_request:
workflow_dispatch:
release:
types: [ published ]
types: [published]
env:
PACKAGE_NAME: trento
OBS_USER: ${{ secrets.OBS_USER }}
OBS_PASS: ${{ secrets.OBS_PASS }}
OBS_PROJECT: ${{ secrets.OBS_PROJECT}}
TARGET_PROJECT: ${{ secrets.TARGET_PROJECT}}
FOLDER: packaging/suse
REPOSITORY: ${{ github.repository }}

jobs:
build:
test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -42,6 +50,35 @@ jobs:
run: make vet-check
- name: coding styles
run: make fmt-check

build:
runs-on: ubuntu-20.04
needs: test
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.16

- uses: actions/setup-node@v2
with:
node-version: "15"
- uses: actions/cache@v2
id: go-cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: actions/cache@v2
id: npm-cache
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: get git tags
run: git fetch --prune --unshallow --tags
- name: build
run: make -j4 cross-compiled
- name: compress
Expand All @@ -60,7 +97,7 @@ jobs:
path: build/trento-amd64.gz

consul-cleanup:
runs-on: [ self-hosted, vmmonitoring ]
runs-on: [self-hosted, vmmonitoring]
needs: build
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
steps:
Expand All @@ -69,7 +106,7 @@ jobs:
uses: ./.github/actions/consul_cleanup

deploy-hana01:
runs-on: [ self-hosted, vmhana01 ]
runs-on: [self-hosted, vmhana01]
needs: consul-cleanup
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
steps:
Expand All @@ -85,7 +122,7 @@ jobs:
role: agent

deploy-hana02:
runs-on: [ self-hosted, vmhana02 ]
runs-on: [self-hosted, vmhana02]
needs: consul-cleanup
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
steps:
Expand All @@ -101,7 +138,7 @@ jobs:
role: agent

deploy-monitoring:
runs-on: [ self-hosted, vmmonitoring ]
runs-on: [self-hosted, vmmonitoring]
needs: consul-cleanup
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
steps:
Expand All @@ -116,11 +153,10 @@ jobs:
with:
role: web


# TODO: This duplication is going to be removed once we make use of the installer
# in the CI
# TODO: This duplication is going to be removed once we make use of the installer
# in the CI
deploy-netweaver01:
runs-on: [ self-hosted, vmnetweaver01 ]
runs-on: [self-hosted, vmnetweaver01]
needs: consul-cleanup
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
steps:
Expand All @@ -136,7 +172,7 @@ jobs:
role: agent

deploy-netweaver02:
runs-on: [ self-hosted, vmnetweaver02 ]
runs-on: [self-hosted, vmnetweaver02]
needs: consul-cleanup
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
steps:
Expand All @@ -152,7 +188,7 @@ jobs:
role: agent

deploy-netweaver03:
runs-on: [ self-hosted, vmnetweaver03 ]
runs-on: [self-hosted, vmnetweaver03]
needs: consul-cleanup
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
steps:
Expand All @@ -168,7 +204,7 @@ jobs:
role: agent

deploy-netweaver04:
runs-on: [ self-hosted, vmnetweaver04 ]
runs-on: [self-hosted, vmnetweaver04]
needs: consul-cleanup
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
steps:
Expand All @@ -195,3 +231,109 @@ jobs:
with:
files: "trento-*"
repo-token: ${{ secrets.GITHUB_TOKEN }}

build-and-push-image:
needs: test
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'release' || github.event_name == 'workflow_dispatch'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
IMAGE_TAG: "${{ github.event_name == 'release' && github.event.release.tag_name || 'rolling' }}"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

commit-obs:
needs: test
runs-on: ubuntu-18.04
if: github.ref == 'refs/heads/main'
container:
image: shap/continuous_deliver
env:
OBS_UNSTABLE: https://download.opensuse.org/repositories/OBS:/Server:/Unstable/SLE_15_SP3/OBS:Server:Unstable.repo
OBS_UNSTABLE_KEY: https://download.opensuse.org/repositories/OBS:/Server:/Unstable/SLE_15_SP3/repodata/repomd.xml.key
GITHUB_OAUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: configure OSC
# OSC credentials must be configured beforehand as the HOME variables cannot be changed from /github/home
# that is used to run osc commands
run: |
/scripts/init_osc_creds.sh
mkdir -p $HOME/.config/osc
cp /root/.config/osc/oscrc $HOME/.config/osc
- name: update go and install obs-service-node_modules
run: |
rpm --import ${OBS_UNSTABLE_KEY}
zypper ar ${OBS_UNSTABLE}
zypper ref
zypper in -y obs-service-node_modules go
go version
- name: prepare tranto.changes file
run: |
VERSION=$(hack/get_version_from_git.sh)
TAG=$(echo $VERSION | cut -f1 -d+)
.ci/gh_release_to_obs_changeset.py $REPOSITORY -a shap-staff@suse.de -t $TAG -f $FOLDER/trento.changes
- name: prepare _service file
run: |
VERSION=$(hack/get_version_from_git.sh)
sed -i 's~%%REVISION%%~${{ github.sha }}~' $FOLDER/_service && \
sed -i 's~%%REPOSITORY%%~${{ github.repository }}~' $FOLDER/_service && \
sed -i 's~%%VERSION%%~'"${VERSION}"'~' $FOLDER/_service
- name: commit changes into OBS
run: cp $FOLDER/_service . && /scripts/upload.sh

submit-obs:
needs: commit-obs
runs-on: ubuntu-18.04
if: github.event.release
container:
image: shap/continuous_deliver
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: configure OSC
run: |
/scripts/init_osc_creds.sh
mkdir -p $HOME/.config/osc
cp /root/.config/osc/oscrc $HOME/.config/osc
- name: prepare _service file
run: |
VERSION=$(hack/get_version_from_git.sh)
sed -i 's~%%REVISION%%~${{ github.sha }}~' $FOLDER/_service && \
sed -i 's~%%REPOSITORY%%~${{ github.repository }}~' $FOLDER/_service && \
sed -i 's~%%VERSION%%~'"${VERSION}"'~' $FOLDER/_service
- name: submit package
run: cp $FOLDER/_service . && /scripts/submit.sh
77 changes: 0 additions & 77 deletions .github/workflows/obs.yml

This file was deleted.

0 comments on commit ce1387e

Please sign in to comment.