v0.0.1 #6
Workflow file for this run
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: Build and deploy app | |
on: | |
release: | |
types: [published] | |
env: | |
TENCENTCLOUD_REGION: ap-guangzhou | |
TENCENTCLOUD_SECRET_KEY: ${{ secrets.TENCENTCLOUD_SECRET_KEY }} | |
TENCENTCLOUD_SECRET_ID: ${{ secrets.TENCENTCLOUD_SECRET_ID }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Get PR number or Release version | |
run: | | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
echo "PR number: ${{ github.event.number }}" | |
echo "RELEASE_VERSION=${{ github.event.number }}" >> $GITHUB_ENV | |
elif [ "${{ github.event_name }}" == "release" ]; then | |
echo "RELEASE_VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV | |
fi | |
- name: Use the PR number or Release version | |
run: echo "PR number or Release version ${RELEASE_VERSION}" | |
- name: Install Packer and Terraform dependencies | |
run: sudo apt-get update && sudo apt-get install -y unzip wget | |
- name: Download and install Packer | |
run: | | |
if ! command -v packer &> /dev/null | |
then | |
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg | |
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list | |
sudo apt update && sudo apt install packer | |
y | sudo mv packer /usr/local/bin/ | |
else | |
echo "Packer is already installed" | |
fi | |
- name: Download and install Packer plugin | |
run: packer plugins install github.com/hashicorp/tencentcloud | |
- name: packer version | |
run: packer version | |
- name: Build image | |
run: | | |
packer build packer/packer_tencentcloud_as_1.0.json | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Install Packer and Terraform dependencies | |
run: sudo apt-get update && sudo apt-get install -y unzip wget | |
- name: Get PR number or Release version | |
run: | | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
echo "PR number: ${{ github.event.number }}" | |
echo "RELEASE_VERSION=${{ github.event.number }}" >> $GITHUB_ENV | |
elif [ "${{ github.event_name }}" == "release" ]; then | |
echo "RELEASE_VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV | |
fi | |
- name: Use the PR number or Release version | |
run: echo "PR number or Release version ${RELEASE_VERSION}" | |
- name: Download and install Terraform | |
run: | | |
VERSION=${RELEASE_VERSION} | |
if ! command -v terraform &> /dev/null | |
then | |
wget https://releases.hashicorp.com/terraform/$RELEASE_VERSION/terraform_$RELEASE_VERSION_linux_amd64.zip | |
unzip terraform_$RELEASE_VERSION_linux_amd64.zip | |
sudo mv terraform /usr/local/bin/ | |
else | |
echo "Terraform is already installed" | |
fi | |
- name: terraform version | |
run: terraform version | |
- name: cd terraform ... | |
run: | | |
cd terraform | |
terraform init | |
terraform apply -auto-approve -var "image_version=${RELEASE_VERSION}" | |