diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a5ca908..7b30a15 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,7 +35,7 @@ jobs: with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 + aws-region: us-west-2 - name: Build, tag, and push the image to Amazon ECR id: build-image @@ -54,3 +54,14 @@ jobs: docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" + + - name: Packer build + uses: ExitoLab/packer_build_action_aws@v0.2.10 + with: + templateFile: 'packer/config.json' + workingDir: '.' + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-west-2 + LEC_VERSION: ${{ steps.version.outputs.new_tag }} diff --git a/packer/config.json b/packer/config.json new file mode 100644 index 0000000..256506b --- /dev/null +++ b/packer/config.json @@ -0,0 +1,47 @@ +{ + "variables": { + "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", + "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", + "aws_region": "us-west-2", + "lec_version": "{{env `LEC_VERSION`}}" + }, + "builders": [ + { + "access_key": "{{user `aws_access_key`}}", + "secret_key": "{{user `aws_secret_key`}}", + "ami_name": "log-export-container@{{user `lec_version`}}", + "instance_type": "t2.micro", + "region": "{{user `aws_region`}}", + "source_ami_filter": { + "filters": { + "virtualization-type": "hvm", + "name": "ubuntu/images/*ubuntu-focal-20.04-amd64-server*", + "root-device-type": "ebs" + }, + "owners": ["099720109477"], + "most_recent": true + }, + "ssh_username": "ubuntu", + "type": "amazon-ebs" + } + ], + "provisioners": [ + { + "type": "file", + "source": "lec-playbook.yml", + "destination": "/home/ubuntu/lec-playbook.yml" + }, + { + "type": "file", + "source": "env-file.example", + "destination": "/home/ubuntu/env-file" + }, + { + "execute_command": "echo 'ubuntu' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'", + "scripts": [ + "packer/install-ansible-and-run-playbook.sh" + ], + "type": "shell" + } + ] +} diff --git a/packer/install-ansible-and-run-playbook.sh b/packer/install-ansible-and-run-playbook.sh new file mode 100644 index 0000000..3e9213e --- /dev/null +++ b/packer/install-ansible-and-run-playbook.sh @@ -0,0 +1,6 @@ +sudo rm -r /var/lib/apt/lists/* +sudo apt update +sudo apt install software-properties-common +sudo apt-add-repository --yes --update ppa:ansible/ansible +sudo apt install ansible -y +sudo ansible-playbook /home/ubuntu/lec-playbook.yml