ci: OC delete specified resources before deployment #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Go Test | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- development # Trigger on push to the development branch | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.22' # Specify the Go version you want to use | |
- name: Run tests | |
run: make test # Run all tests | |
- name: Build application | |
run: make build | |
# Setup S2i and Build container image | |
# s2i build and upload to quay | |
- name: Install s2i | |
run: | | |
wget https://github.com/openshift/source-to-image/releases/download/v1.1.14/source-to-image-v1.1.14-874754de-linux-386.tar.gz | |
tar -xvf source-to-image-v1.1.14-874754de-linux-386.tar.gz | |
sudo mv s2i /usr/local/bin | |
- name: s2i-build | |
run: | | |
sudo s2i build . quay.io/rh-ee-kmemane/go-s2i-builder quay.io/rh-ee-kmemane/area-calculator | |
sudo docker images | |
# Push Image to Quay registry | |
- name: Push Application image to quay | |
run: | | |
sudo docker login quay.io -u "${{ secrets.QUAY_USERNAME }}" -p "${{ secrets.QUAY_PASSWORD }}" | |
sudo docker push quay.io/rh-ee-kmemane/area-calculator | |
# deploy application in resource hub | |
- name: Authenticate and set context | |
uses: redhat-actions/oc-login@v1 | |
env: | |
OPENSHIFT_USER: rh-ee-kmemane | |
OPENSHIFT_NAMESPACE: rh-ee-kmemane-dev | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} | |
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | |
insecure_skip_tls_verify: true | |
namespace: ${{ env.OPENSHIFT_NAMESPACE }} | |
- name: Deploy application | |
run: | | |
if oc get svc -l app=area-calculator --ignore-not-found; then | |
oc delete svc,deployment,route,imagestream --selector app=area-calculator; | |
echo "deleted all resources with label app=area-calculator"; | |
fi | |
oc new-app quay.io/rh-ee-kmemane/area-calculator --name=area-calculator | |
oc expose svc area-calculator | |
oc get routes |