Skip to content

Commit 3358bb5

Browse files
committed
Update OCI workflow to deploy with container instances
Revised the deployment pipeline to target Oracle Cloud Container Instances instead of generic OCI. Changes include switching to OCI CLI for setup, improving image tagging, and streamlining container deployment steps for better compatibility and maintainability.
1 parent 3b09a0d commit 3358bb5

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

.github/workflows/deploy-to-oci.yml

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,59 @@
1-
name: Deploy to Oracle Cloud Infrastructure
1+
name: Deploy to Oracle Cloud Container Instance
22

33
on:
44
push:
55
branches: [ main ]
6+
workflow_dispatch:
67

78
jobs:
89
build-and-deploy:
910
runs-on: ubuntu-latest
1011

1112
steps:
1213
- name: Checkout code
13-
uses: actions/checkout@v3
14+
uses: actions/checkout@v2
1415

15-
- name: Set up Docker Buildx
16-
uses: docker/setup-buildx-action@v2
17-
18-
- name: Login to Oracle Cloud Infrastructure Registry
19-
uses: docker/login-action@v2
20-
with:
21-
registry: ${{ secrets.OCI_REGISTRY }}
22-
username: ${{ secrets.OCI_USERNAME }}
23-
password: ${{ secrets.OCI_AUTH_TOKEN }}
24-
25-
- name: Build and push Docker image
26-
uses: docker/build-push-action@v4
16+
- name: Set up OCI CLI
17+
uses: oracle-actions/setup-oci-cli@v1
2718
with:
28-
context: .
29-
push: true
30-
tags: ${{ secrets.OCI_REGISTRY }}/${{ secrets.OCI_NAMESPACE }}/adminhubapi:${{ github.sha }}
19+
user-id: ${{ secrets.OCI_USER_OCID }}
20+
fingerprint: ${{ secrets.OCI_FINGERPRINT }}
21+
private-key: ${{ secrets.OCI_PRIVATE_KEY }}
22+
tenancy-id: ${{ secrets.OCI_TENANCY_OCID }}
23+
region: ${{ secrets.OCI_REGION }}
3124

32-
- name: Install OCI CLI
25+
- name: Login to Oracle Cloud Container Registry
3326
run: |
34-
curl -L -O https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh
35-
chmod +x install.sh
36-
./install.sh --accept-all-defaults
37-
echo "$HOME/lib/oracle-cli/bin" >> $GITHUB_PATH
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 }}
3828
39-
- name: Configure OCI CLI
29+
- name: Build and Push Docker Image
4030
run: |
41-
mkdir -p ~/.oci
42-
echo "${{ secrets.OCI_CONFIG }}" > ~/.oci/config
43-
echo "${{ secrets.OCI_KEY }}" > ~/.oci/key.pem
44-
chmod 600 ~/.oci/key.pem
45-
46-
- name: Deploy to OCI Container Instance
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
4745
run: |
46+
# Create or update container instance
4847
oci container-instances container-instance create \
4948
--compartment-id ${{ secrets.OCI_COMPARTMENT_ID }} \
5049
--availability-domain ${{ secrets.OCI_AVAILABILITY_DOMAIN }} \
51-
--shape ${{ secrets.OCI_SHAPE }} \
52-
--container-restart-policy ALWAYS \
53-
--containers '[{"image":"${{ secrets.OCI_REGISTRY }}/${{ secrets.OCI_NAMESPACE }}/adminhubapi:${{ github.sha }}","displayName":"adminhubapi"}]'
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

0 commit comments

Comments
 (0)