1- name : Deploy to Oracle Cloud Container Instance
1+ name : Deploy to OCI Container Instances
22
33on :
44 push :
55 branches : [ main ]
6- workflow_dispatch :
76
87jobs :
98 build-and-deploy :
109 runs-on : ubuntu-latest
1110
1211 steps :
13- - name : Checkout code
14- uses : actions/checkout@v3
12+ - uses : actions/checkout@v3
1513
16- - name : Set up OCI CLI
17- uses : oracle- actions/configure-oci-credentials@v1
14+ - name : Set up .NET
15+ uses : actions/setup-dotnet@v3
1816 with :
19- key-id : ${{ secrets.OCI_USER_OCID }}
20- fingerprint : ${{ secrets.OCI_FINGERPRINT }}
21- key-content : ${{ secrets.OCI_PRIVATE_KEY }}
22- tenancy-id : ${{ secrets.OCI_TENANCY_OCID }}
23- region : ${{ secrets.OCI_REGION }}
17+ dotnet-version : ' 9.0.x'
2418
25- - name : Login to Oracle Cloud Container Registry
19+ - name : Build and publish
2620 run : |
27- oci artifacts container repository login --username ${{ secrets.OCI_USER_OCID }} --password-stdin <<< "${{ secrets.OCI_AUTH_TOKEN }}" --region ${{ secrets.OCI_REGION }} --registry ${{ secrets.OCI_REGISTRY }}
21+ dotnet restore
22+ dotnet build --configuration Release
23+ dotnet publish --configuration Release --output ./publish
2824
29- - name : Build and Push Docker Image
30- run : |
31- # Get timestamp for unique tag
32- timestamp=$(date +%Y%m%d%H%M%S)
33-
34- # Build the Docker image
35- docker build -t ${{ secrets.OCI_REGISTRY }}/${{ secrets.REPOSITORY_NAME }}:$timestamp -t ${{ secrets.OCI_REGISTRY }}/${{ secrets.REPOSITORY_NAME }}:latest .
36-
37- # Push the Docker image
38- docker push ${{ secrets.OCI_REGISTRY }}/${{ secrets.REPOSITORY_NAME }}:$timestamp
39- docker push ${{ secrets.OCI_REGISTRY }}/${{ secrets.REPOSITORY_NAME }}:latest
40-
41- # Save the image tag for later use
42- echo "IMAGE_TAG=$timestamp" >> $GITHUB_ENV
43-
44- - name : Deploy to Oracle Cloud Container Instance
45- run : |
46- # Create or update container instance
47- oci container-instances container-instance create \
48- --compartment-id ${{ secrets.OCI_COMPARTMENT_ID }} \
49- --availability-domain ${{ secrets.OCI_AVAILABILITY_DOMAIN }} \
50- --display-name "admin-hub-api" \
51- --shape "VM.Standard.E2.1.Micro" \
52- --shape-config '{"ocpus": 1, "memoryInGBs": 1}' \
53- --vnics '[{"subnetId": "${{ secrets.OCI_SUBNET_ID }}", "displayName": "primary-vnic"}]'
54- --containers '[{
55- "displayName": "admin-hub-api",
56- "imageUrl": "${{ secrets.OCI_REGISTRY }}/${{ secrets.REPOSITORY_NAME }}:${{ env.IMAGE_TAG }}",
57- "isResourcePrincipalDisabled": true
58- }]' \
59- --wait-for-state SUCCEEDED
25+ - name : Set up Docker Buildx
26+ uses : docker/setup-buildx-action@v2
27+
28+ - name : Login to Oracle Cloud Infrastructure Registry
29+ uses : docker/login-action@v2
30+ with :
31+ registry : ${{ secrets.OCI_REGISTRY }}
32+ username : ${{ secrets.OCI_USERNAME }}
33+ password : ${{ secrets.OCI_PASSWORD }}
34+
35+ - name : Build and push Docker image
36+ uses : docker/build-push-action@v4
37+ with :
38+ context : .
39+ push : true
40+ tags : ${{ secrets.OCI_REGISTRY }}/${{ secrets.OCI_REPOSITORY }}:${{ github.sha }}
41+
42+ - name : Deploy to Container Instances
43+ uses : oracle-actions/run-oci-cli-command@v1
44+ with :
45+ command : container-instances create-container-instance
46+ args : |
47+ --compartment-id ${{ secrets.OCI_COMPARTMENT_ID }}
48+ --availability-domain ${{ secrets.OCI_AVAILABILITY_DOMAIN }}
49+ --shape ${{ secrets.OCI_SHAPE }}
50+ --display-name my-app
51+ --container-config '[{"image":"${{ secrets.OCI_REGISTRY }}/${{ secrets.OCI_REPOSITORY }}:${{ github.sha }}"}]'
0 commit comments