Skip to content

Commit

Permalink
update playbook to build docker-image
Browse files Browse the repository at this point in the history
  • Loading branch information
iknowright committed Feb 28, 2023
1 parent 10ee3d6 commit 5026682
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ jobs:

- name: Decode private key file
run: |
echo "${{secrets.PRODUCTION_DOT_ENV_FILE}}" > .env
echo "${{secrets.SSH_PRIVATE_KEY}}" | base64 --decode > "private.pem"
chmod 400 private.pem
- name: Run playbook
- name: Run CD playbook
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: deploy.yml
Expand All @@ -26,4 +27,3 @@ jobs:
ansible_user: changchaishi
ansible_ssh_private_key_file: private.pem
ansible_python_interpreter: /usr/bin/python3
34 changes: 28 additions & 6 deletions deploy.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
---
- name: Check services
hosts: staging
# need to use become since I'm connecting using personal private key
become: true
# switch user as dev
become_user: dev
vars:
project_dir: /home/dev/web-projects/pycontw-2023-ansible

tasks:
- name: Ensure that sshd is started
- name: Ensure that Docker for python is present (docker in pip)
community.general.python_requirements_info:
dependencies:
- docker

- name: Get info on docker host and list images
community.docker.docker_host_info:
images: true
become: true
register: result
- name: Create a directory if it does not exist
ansible.builtin.file:
path: "{{ project_dir }}"
state: directory

- name: Copy entire project files to remote server
ansible.builtin.copy:
src: .
dest: "{{ project_dir }}"

- name: Ensure docker network network-2023 exists
community.docker.docker_network:
name: network-2023

- name: Build and start service
community.docker.docker_compose:
project_src: web-projects/pycontw-2023-ansible
build: true
# try to build first, without up the service
state: present

3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ version: "3.5"
services:
web:
build: .
container_name: pycontw-2023
container_name: pycontw-2023-ansible
image: pycontw-2023_web-ansible
hostname: pycontw-2023
entrypoint: ""
command:
Expand Down

0 comments on commit 5026682

Please sign in to comment.